﻿using CsharpHttpHelper;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;

using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Web;
using System.Runtime.InteropServices;

namespace AutoSend
{
    public partial class frmMain : Form
    {
        DateTime shutstart;
        DateTime softdt;
        public TextBox lispic;
        public TextBox txtCity;
        public TextBox txtJuZi;
        public TextBox randpic;
        public DateTime dts;
        public DateTime dte;
        public bool isstoppub = true;
        public bool ispics = true;//选中的是图片还是随机图片，用于移除图片地址功能。
        public int pubnum = 0;
        public bool ispausd = false;
        public int waitsecond = 0;
        public bool isstarttime = false;
        public string titleurl = "";
        private string _login_name;
        private string _login_pass;
        Thread t = null;
        TimeSpan regtime;
        public int twoid = -1;
        //关机功能
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        internal struct TokPriv1Luid
        {
            public int Count;
            public long Luid;
            public int Attr;
        }
        [DllImport("kernel32.dll", ExactSpelling = true)]
        internal static extern IntPtr GetCurrentProcess();

        [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
        internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr phtok);

        [DllImport("advapi32.dll", SetLastError = true)]
        internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid);

        [DllImport("advapi32.dll", ExactSpelling = true, SetLastError = true)]
        internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
         ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);

        [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)]
        internal static extern bool ExitWindowsEx(int flg, int rea);

        internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
        internal const int TOKEN_QUERY = 0x00000008;
        internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
        internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
        internal const int EWX_LOGOFF = 0x00000000;
        internal const int EWX_SHUTDOWN = 0x00000001;
        internal const int EWX_REBOOT = 0x00000002;
        internal const int EWX_FORCE = 0x00000004;
        internal const int EWX_POWEROFF = 0x00000008;
        internal const int EWX_FORCEIFHUNG = 0x00000010;

        private void DoExitWin(int flg)
        {
            bool ok;
            TokPriv1Luid tp;
            IntPtr hproc = GetCurrentProcess();
            IntPtr htok = IntPtr.Zero;
            ok = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
            tp.Count = 1;
            tp.Luid = 0;
            tp.Attr = SE_PRIVILEGE_ENABLED;
            ok = LookupPrivilegeValue(null, SE_SHUTDOWN_NAME, ref tp.Luid);
            ok = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
            ok = ExitWindowsEx(flg, 0);
        }

        public frmMain(string name, string pass)
        {
            this._login_name = name;
            this._login_pass = pass;

            Control.CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
        }

        private void 官方网站ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(Myinfo.ip);
        }
        public static void InitMenu(ToolStripMenuItem tsMi, EventHandler e)
        {
            DirectoryInfo dirinfo = new DirectoryInfo(Application.StartupPath + @"\skins");
            string str, filename;
            ToolStripMenuItem temp = new ToolStripMenuItem();
            temp.Text = "默认";
            temp.Tag = "no";
            temp.Click += new EventHandler(e);
            tsMi.DropDownItems.Add(temp);
            FileInfo[] allfile = null;
            if (Directory.Exists(Application.StartupPath + @"\skins"))
                allfile = dirinfo.GetFiles("*.ssk");
            if (allfile != null)
                foreach (FileInfo fi in allfile)
                {
                    temp = new ToolStripMenuItem();
                    str = fi.Name;
                    filename = str.Substring(0, str.IndexOf('.'));
                    temp.Text = filename;
                    temp.Tag = fi.FullName;
                    temp.Click += new EventHandler(e);
                    tsMi.DropDownItems.Add(temp);
                }
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            txtName.Text = this._login_name;
            lispic = this.txtPics;
            txtCity = this.txtzhubl;
            txtJuZi = this.txtjz;
            randpic = this.txtrandpic;
            lispic = this.txtPics;
            regtime = Myinfo.softtime;
            //InitMenu(this.tsMi, toolStripMenu_Click);
            this.tsslName.Text = "用户：" + Myinfo.username;
            //this.tsslPhone.Text = "咨询电话：" + Myinfo.phone;
            //this.tsslTime.Text = "剩余时间：" + AShelp.DateDiff(softdt, DateTime.Now);
            this.Text = Myinfo.sname + Myinfo.comname;
            List<string> source = AShelp.Load(Myinfo.username + "\\usernet");
            if (source != null)
            {
                this.txtName.Text = source[0];
                this.txtPwd.Text = source[1];
            }
            comboBox6.SelectedIndex = 0;
            comboBox3.Text = "供应";
            comboBox4.Text = "求购";
            picCode.Image = myhttp.getCodeimage("http://b2b.sg560.com/CheckCode.aspx?0." + (new Random().Next().ToString()));
            initData();
            myhttp.getStrjs();
        }
        private void initData()
        {
            string[] configs = AShelp.GetConfigs();
            foreach (string s in configs)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = s;
                lvi.ImageIndex = 0;
                this.lsvConfig.Items.Add(lvi);
            }
            List<string> source = AShelp.LoadConfig("use");
            if (source != null && source.Count > 0)
            {
                Myinfo.configname = source[0];
                lblconfig.Text = "当前配置是：" + Myinfo.configname;
            }
            LoadConfig();
            UpdateTabNum();

        }

        private void LoadConfig()
        {
            List<string> dl = AShelp.LoadWZ("adddl");
            if (dl != null && dl.Count == 16)
            {

                if (dl[0]=="1")
                    radioButton4.Checked=true;
                else
                    radioButton6.Checked = true; 
                textBox10.Text=dl[1];
                if (dl[2] == "1")
                    radioButton9.Checked=true;
                else
                    radioButton8.Checked = true;
                textBox11.Text=dl[3];

                if (dl[4] == "1")
                    radioButton11.Checked = true;
                else
                    radioButton10.Checked = true;
                textBox12.Text = dl[5];
                if (dl[6] == "1")
                    radioButton13.Checked = true;
                else
                    radioButton12.Checked = true;
                textBox13.Text = dl[7];
                if (dl[8] == "1")
                    radioButton15.Checked = true;
                else
                    radioButton14.Checked = true;
                textBox14.Text = dl[9];
                if (dl[10] == "1")
                    radioButton17.Checked = true;
                else
                    radioButton16.Checked = true;
                textBox15.Text = dl[11];
                if (dl[12] == "1")
                    radioButton21.Checked = true;
                else
                    radioButton20.Checked = true;
                textBox18.Text = dl[13];
               
                txtdl5.Text=dl[14];
                txtdl6.Text = dl[15];
            }

            //修改当前使用配置的图标状态
            for (int i = 0; i < this.lsvConfig.Items.Count; i++)
            {
                if (Myinfo.configname == this.lsvConfig.Items[i].Text)
                {
                    this.lsvConfig.Items[i].ImageIndex = 1;
                    break;
                }
            }
            //修改HTML视图
            string[] mbs = AShelp.GetHtmls();
            ckbHtml.Items.Clear();
            if (mbs != null)
            {
                foreach (string mb in mbs)
                {
                    ckbHtml.Items.Add(mb);
                }
            }
            List<string> ckdhtml = AShelp.LoadWZ("ckdhtml");
            if (ckdhtml != null)
            {
                foreach (string ckdh in ckdhtml)
                {
                    for (int i = 0; i < this.ckbHtml.Items.Count; i++)
                    {
                        if (ckbHtml.GetItemText(ckbHtml.Items[i]) == ckdh)
                            this.ckbHtml.SetItemChecked(i, true);
                    }
                }
            }

            List<string> wz = AShelp.LoadWZ("WZ");
            if (wz != null && wz.Count == 28)
            {
                txtzhubl.Text = wz[0];
                txtbl1.Text = wz[1];
                if (wz[2] == "1")
                    ckbbl1.Checked = true;
                txtbl2.Text = wz[3];
                if (wz[4] == "1")
                    ckbbl2.Checked = true;
                txtbl3.Text = wz[5];
                if (wz[6] == "1")
                    ckbbl3.Checked = true;
                txtjz.Text = wz[7];
                txtranda.Text = wz[8];
                txtrandpic.Text = wz[9];
                txtdl1.Text = wz[10];
                if (wz[11] == "0")
                    rbtdl1r.Checked = false;
                txtdl1row.Text = wz[12];
                txtdl2.Text = wz[13];
                if (wz[14] == "0")
                    rbtdl2r.Checked = false;
                txtdl2row.Text = wz[15];
                txtdl3.Text = wz[16];
                if (wz[17] == "0")
                    rbtdl3r.Checked = false;
                txtdl3row.Text = wz[18];
                txtdl4.Text = wz[19];
                if (wz[20] == "0")
                    rbtdl4r.Checked = false;
                txtdl4row.Text = wz[21];

                txtTitle.Text = wz[22];
                if (wz[23] == "0")
                    ckbSCDL.Checked = false;
                txtkeyword1.Text = wz[24];
                txtkeyword2.Text = wz[25];
                txtkeyword3.Text = wz[26];
                txttishi.Text = wz[27];

            }
            List<string> add = AShelp.LoadWZ("add");
            if (add != null)
            {
                textBox31.Text = add[0];
            }
            List<infos> df = AShelp.LoadTitle("df");
            lsvdaifa.Items.Clear();
            if (df != null)
            {

                foreach (infos minfo in df)
                {
                    ListViewItem lsv = new ListViewItem();
                    lsv.Text = minfo.title;
                    lsv.SubItems.Add(minfo.info);
                    this.lsvdaifa.Items.Add(lsv);
                }
                label45.Text = string.Format("共有{0}个信息待发", df.Count);
            }
            List<infos> cg = AShelp.LoadTitle("cg");
            lsvchenggong.Items.Clear();
            if (cg != null)
            {

                foreach (infos minfo in cg)
                {
                    ListViewItem lsv = new ListViewItem();
                    lsv.Text = minfo.title;
                    lsv.SubItems.Add(minfo.info);
                    this.lsvchenggong.Items.Add(lsv);
                }
            }
            List<infos> sb = AShelp.LoadTitle("sb");
            lsvshibai.Items.Clear();
            if (sb != null)
            {

                foreach (infos minfo in sb)
                {
                    ListViewItem lsv = new ListViewItem();
                    lsv.Text = minfo.title;
                    lsv.SubItems.Add(minfo.info);
                    this.lsvshibai.Items.Add(lsv);
                }
            }
            UpdateTabNum();
            List<string> ts = AShelp.LoadWZ("ts");
            if (ts != null && ts.Count >= 32)
            {
                txtSinterval.Text = ts[0];
                txtEinterval.Text = ts[1];
                if (ts[2] == "0")
                {
                    rbpubtbig.Checked = false;
                    rbpubtnum.Checked = true;
                }
                txtPubnum.Text = ts[3];
                if (ts[4] == "1")
                    ckbfb1.Checked = true;
                if (ts[5] == "1")
                    ckbfb2.Checked = true;
                if (ts[6] == "1")
                    ckbfb3.Checked = true;
                if (ts[7] == "1")
                    ckbfb4.Checked = true;
                if (ts[8] == "1")
                    ckblinkpre.Checked = true;
                if (ts[9] == "1")
                    ckbshut.Checked = true;
                if (ts[10] == "0")
                    radioButton2.Checked = true;
                txtmini.Text = ts[11];
                txtPics.Text = ts[12];
                List<DropDL> list = AShelp.LoadDropDL("cb1");
                if (list != null)
                {
                    comboBox1.DataSource = list;
                    comboBox1.DisplayMember = "text";
                    comboBox1.ValueMember = "value";
                    comboBox1.Text = ts[13];
                }

                List<DropDL> list2 = AShelp.LoadDropDL("cb2");
                if (list2 != null)
                {
                    comboBox2.DataSource = list2;
                    comboBox2.DisplayMember = "text";
                    comboBox2.ValueMember = "value";
                    comboBox2.Text = ts[14];
                }
                List<DropDL> listn = AShelp.LoadDropDL("cbn");
                if (listn != null)
                {
                    comboBox8.DataSource = listn;
                    comboBox8.DisplayMember = "text";
                    comboBox8.ValueMember = "value";
                    comboBox8.SelectedText = ts[30];
                }
                List<Category> one = AShelp.LoadCategory("one");
                if (one != null)
                {
                    cbbone.DataSource = one;
                    cbbone.DisplayMember = "Name";
                    cbbone.ValueMember = "Id";
                    cbbone.Text = ts[15];
                }
                List<Category> two = AShelp.LoadCategory("two");
                if (two != null)
                {
                    cbbtwo.DataSource = two;
                    cbbtwo.DisplayMember = "Name";
                    cbbtwo.ValueMember = "Id";
                    cbbtwo.Text = ts[16];
                }
                List<string> addid = AShelp.LoadWZ("addid");
                if (addid != null)
                {
                    if (addid[0] != "0")
                    {
                        int i = 0;
                        int.TryParse(addid[0], out i);
                        twoid = i;
                        cbbtwo.Enabled = false;
                    }
                }
                List<Category> three = AShelp.LoadCategory("three");
                if (three != null)
                {
                    cbbthree.DataSource = three;
                    cbbthree.DisplayMember = "Name";
                    cbbthree.ValueMember = "Id";
                    cbbthree.Text = ts[17];
                }

                comboBox6.SelectedItem = ts[18];
                textBox1.Text = ts[19];
                textBox2.Text = ts[20];
                textBox3.Text = ts[21];
                textBox4.Text = ts[22];
                textBox5.Text = ts[23];
                textBox6.Text = ts[24];
                textBox7.Text = ts[25];
                textBox8.Text = ts[26];
                textBox9.Text = ts[27];
                comboBox3.Text = ts[28];
                comboBox4.Text = ts[29];
                if (ts[31] != "")
                    comboBox7.Text = ts[31];
                else
                    comboBox7.Text = "企业动态";
                if(ts.Count>=33)
                    comboBox5.Text = ts[32];
            }
            else
            {
                comboBox3.Text = "供应";
                comboBox4.Text = "求购";
                comboBox7.Text = "企业动态";

            }
        }
        //private void toolStripMenu_Click(object sender, EventArgs e)
        //{
        //    ToolStripMenuItem temp = (ToolStripMenuItem)sender;
        //    if (temp.Tag.ToString() != "no")
        //    {
        //        Myinfo.skin.SkinFile = temp.Tag.ToString();
        //        Myinfo.skin.Active = true;
        //        Myinfo.skin.SkinAllForm = true;
        //    }
        //    else
        //    {
        //        Myinfo.skin.Active = false;
        //    }
        //    AShelp.UpdateAppConfig("skinname", temp.Tag.ToString());
        //}


        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (MessageBox.Show("您真的要退出吗？", "提示", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                e.Cancel = true;
            }
            else
            {
                SaveConfig();
            }
        }

        private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            string key = "AutoSend";
            string iv = "weiwei@1";

            string strPass = this._login_name + "|" + this._login_pass + "|" + Myinfo.sid + "|" + DateTime.Now;

            string md5strPass = Tools.Encode(strPass, key, iv);

            WebReference2.Heart hwm = new WebReference2.Heart();


            //result:0|时间，代表退出失败，1|时间，代表退出成功
            try
            {
                string result = hwm.SetIsUse(md5strPass);

                string re = Tools.Decode(result, key, iv);
            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("无法连接到远程服务器"))
                {
                    MessageBox.Show("无法连接到远程服务器,程序将退出！");
                }

            }
            finally
            {

                Application.ExitThread();
            }
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            if (regtime.TotalSeconds > 0)
                this.tsslTime.Text = "剩余时间：" + AShelp.DateDiff(ref regtime);
            else
            {
                if (t != null)
                    t.Abort();
                timer1.Stop();
                MessageBox.Show("软件已到期,请联系软件公司！");
                Application.ExitThread();
            }
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }
        private void btnshow_Click(object sender, EventArgs e)
        {
            if (txtPwd.PasswordChar == '*')
            {
                txtPwd.PasswordChar = '\0';
                btnshow.Text = "隐";
            }
            else
            {
                txtPwd.PasswordChar = '*';
                btnshow.Text = "显";
            }
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            lbllogininfo.Text = "正在登录，请耐心等待！";
            btnLogin.Enabled = false;
            lbllogininfo.Refresh();
            btnLogin.Refresh();
            string name = txtName.Text.Trim();
            string pwd = txtPwd.Text.Trim();
            string code = txtCode.Text.Trim();
            //http://b2b.sg560.com/login.aspx
            Loginstatus objjson = myhttp.Login(name, pwd, code);
            if (objjson != null && objjson.status.ToLower() == "y")
            {
                lbllogininfo.Text = "登录成功！";
                btnLogin.Enabled = false;
                myhttp.mainurl = objjson.info;
                myhttp.myid = myhttp.getmyid(myhttp.mainurl);
                myhttp.sgid = myhttp.getmysgid(myhttp.mainurl, "index");
                myhttp.islogin = "OK";
                if (ckbremenberme.Checked)
                {
                    AShelp.Save(this.txtName.Text, this.txtPwd.Text, "", "", Myinfo.username + "\\usernet");
                }
            }
            else
            {
                lbllogininfo.Text = "登录不成功！";
                MessageBox.Show(objjson.info, "提示");
                btnLogin.Enabled = true;
                picCode_Click(null, null);
            }

        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            HttpResult result = myhttp.HttpGet("http://b2b.sg560.com/login.aspx?spa=logout", "");
            btnLogin.Enabled = true;
            lbllogininfo.Text = "退出成功！";
        }

        private void picCode_Click(object sender, EventArgs e)
        {
            picCode.Image = myhttp.getCodeimage("http://b2b.sg560.com/CheckCode.aspx?0." + (new Random().Next().ToString()));
        }

        private void ckbremenberme_Click(object sender, EventArgs e)
        {
            if (ckbremenberme.Checked)
            {

            }
        }

        private void btnimgmanager_Click(object sender, EventArgs e)
        {
            frmimg f = new frmimg(this);
            f.TopMost = true;
            f.Show();

        }

        private void button46_Click(object sender, EventArgs e)
        {
            txtmbname.Focus();
            this.htmlEditor1.PasteIntoSelection("【标题】");
            this.htmlEditor1.Focus();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (myhttp.islogin == "OK")
            {
                button1.Enabled = false;
                button1.Refresh();
                List<Category> source = myhttp.LoadCategory("");
                cbbone.DataSource = source;
                cbbone.DisplayMember = "Name";
                cbbone.ValueMember = "Id";
                //cbbone.SelectedIndex = 26;                
                int i = myhttp.getconeid(out twoid);
                if (i != 0)
                {
                    cbbone.SelectedIndex = i - 1;
                    cbbone.Enabled = false;
                }
                else
                {
                    cbbone.Enabled = true;
                }

                AShelp.SaveCategory(source, "one");
                List<DropDL> list = myhttp.GetDDL("http://b2b.sg560.com/handler/CpSort.ashx?type=0&cid=" + myhttp.myid, "");
                if (list == null)
                {
                    list = new List<DropDL>();
                }
                list.Insert(0, new DropDL() { text = "==选择一级分类==", value = "0" });

                comboBox1.DataSource = list;
                comboBox1.DisplayMember = "text";
                comboBox1.ValueMember = "value";
                comboBox1.SelectedValue = "0";
                AShelp.SaveDropDL(list, "cb1");

                List<DropDL> listn = myhttp.GetDDL("http://b2b.sg560.com/handler/NewsSort.ashx?type=0&cid=" + myhttp.myid, "");
                if (listn == null)
                {
                    listn = new List<DropDL>();
                }
                listn.Insert(0, new DropDL() { text = "==选择分类==", value = "0" });
                comboBox8.DataSource = listn;
                comboBox8.DisplayMember = "text";
                comboBox8.ValueMember = "value";
                comboBox8.SelectedValue = "0";
                AShelp.SaveDropDL(list, "cbn");
                button1.Enabled = true;
                button1.Refresh();
            }
            else
            {
                MessageBox.Show("请先登录再操作！");
            }

        }

        private void cbbone_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbbone.SelectedIndex != 0)
            {
                List<Category> list2 = myhttp.LoadChildren("0_" + cbbone.SelectedIndex);
                if (list2.Count > 0)
                {
                    cbbtwo.DataSource = list2;
                    cbbtwo.DisplayMember = "Name";
                    cbbtwo.ValueMember = "Id";
                    AShelp.SaveCategory(list2, "two");
                    //cbbtwo.SelectedIndex = -1;
                    if (twoid != 0)
                    {
                        cbbtwo.Enabled = false;
                        cbbtwo.SelectedValue = twoid.ToString();
                        //cbbtwo.SelectedValue = twoid;
                    }
                }
            }
        }

        private void cbbtwo_SelectedIndexChanged(object sender, EventArgs e)
        {
            List<Category> list2 = myhttp.LoadChildren("0_" + cbbone.SelectedIndex + "_" + cbbtwo.SelectedIndex);
            if (list2.Count > 0)
            {
                cbbthree.DataSource = list2;
                cbbthree.DisplayMember = "Name";
                cbbthree.ValueMember = "Id";
                AShelp.SaveCategory(list2, "three");
            }
            else
            {
                cbbthree.DataSource = null;

            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedValue != null)
                if (comboBox1.SelectedValue.ToString() != "0")
                {
                    List<DropDL> list = myhttp.GetDDL("http://b2b.sg560.com/handler/CpSort.ashx?type=1&cid=" + comboBox1.SelectedValue, "");
                    if (list == null)
                    {
                        list = new List<DropDL>();
                    }
                    list.Insert(0, new DropDL() { text = "==选择二级分类==", value = "0" });
                    comboBox2.DataSource = list;
                    comboBox2.DisplayMember = "text";
                    comboBox2.ValueMember = "value";
                    comboBox2.SelectedValue = "0";
                    AShelp.SaveDropDL(list, "cb2");
                }
        }

        private void txtPics_TextChanged(object sender, EventArgs e)
        {
            this.groupBox1.Text = string.Format("标题图片，共有{0}行", txtPics.Lines.Length);
        }

        private void button21_Click(object sender, EventArgs e)
        {
            frmareacs f = new frmareacs(this);
            f.TopMost = true;
            f.Show();
        }

        private void button19_Click(object sender, EventArgs e)
        {
            txtzhubl.Text = "";
        }

        private void button20_Click(object sender, EventArgs e)
        {
            string[] s = txtzhubl.Lines;
            txtzhubl.Lines = AShelp.RandomStrings(s);
        }

        private void button26_Click(object sender, EventArgs e)
        {
            txtbl1.Text = "";
        }

        private void button25_Click(object sender, EventArgs e)
        {
            string[] s = txtbl1.Lines;
            txtbl1.Lines = AShelp.RandomStrings(s);
        }

        private void txtzhubl_TextChanged(object sender, EventArgs e)
        {
            label25.Text = string.Format("主变量，共有{0}行", txtzhubl.Lines.Length);
        }

        private void button24_Click(object sender, EventArgs e)
        {
            txtbl2.Text = "";
        }

        private void button23_Click(object sender, EventArgs e)
        {
            string[] s = txtbl2.Lines;
            txtbl2.Lines = AShelp.RandomStrings(s);
        }

        private void button28_Click(object sender, EventArgs e)
        {
            txtbl3.Text = "";
        }

        private void button27_Click(object sender, EventArgs e)
        {
            string[] s = txtbl3.Lines;
            txtbl3.Lines = AShelp.RandomStrings(s);
        }

        private void txtbl2_TextChanged(object sender, EventArgs e)
        {
            label27.Text = string.Format("变量2，共有{0}行", txtbl2.Lines.Length);

        }

        private void txtbl1_TextChanged(object sender, EventArgs e)
        {
            label26.Text = string.Format("变量1，共有{0}行", txtbl1.Lines.Length);
        }

        private void txtbl3_TextChanged(object sender, EventArgs e)
        {
            label28.Text = string.Format("变量3，共有{0}行", txtbl3.Lines.Length);
        }

        private void button22_Click(object sender, EventArgs e)
        {
            frmkeyword f = new frmkeyword(this);
            f.TopMost = true;
            f.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (txtzhubl.Lines.Length > 0)
                txtTitle.Text += "【主变量】";
            else
                MessageBox.Show("主变量没有数据");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (txtbl1.Lines.Length > 0)
                txtTitle.Text += "【变量1】";
            else
                MessageBox.Show("变量1没有数据");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (txtbl2.Lines.Length > 0)
                txtTitle.Text += "【变量2】";
            else
                MessageBox.Show("变量2没有数据");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (txtbl3.Lines.Length > 0)
                txtTitle.Text += "【变量3】";
            else
                MessageBox.Show("变量3没有数据");
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (txtzhubl.Lines.Length > 0)
                txtkeyword1.Text += "【主变量】";
            else
                MessageBox.Show("主变量没有数据");

        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (txtbl1.Lines.Length > 0)
                txtkeyword1.Text += "【变量1】";
            else
                MessageBox.Show("变量1没有数据");

        }

        private void button8_Click(object sender, EventArgs e)
        {
            if (txtbl2.Lines.Length > 0)
                txtkeyword1.Text += "【变量2】";
            else
                MessageBox.Show("变量2没有数据");
        }

        private void button7_Click(object sender, EventArgs e)
        {
            if (txtbl3.Lines.Length > 0)
                txtkeyword1.Text += "【变量3】";
            else
                MessageBox.Show("变量3没有数据");
        }

        private void button14_Click(object sender, EventArgs e)
        {
            if (txtzhubl.Lines.Length > 0)
                txtkeyword2.Text += "【主变量】";
            else
                MessageBox.Show("主变量没有数据");
        }

        private void button13_Click(object sender, EventArgs e)
        {
            if (txtbl1.Lines.Length > 0)
                txtkeyword2.Text += "【变量1】";
            else
                MessageBox.Show("变量1没有数据");
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if (txtbl2.Lines.Length > 0)
                txtkeyword2.Text += "【变量2】";
            else
                MessageBox.Show("变量2没有数据");
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (txtbl3.Lines.Length > 0)
                txtkeyword2.Text += "【变量3】";
            else
                MessageBox.Show("变量3没有数据");
        }

        private void button18_Click(object sender, EventArgs e)
        {
            if (txtzhubl.Lines.Length > 0)
                txtkeyword3.Text += "【主变量】";
            else
                MessageBox.Show("主变量没有数据");
        }

        private void button17_Click(object sender, EventArgs e)
        {
            if (txtbl1.Lines.Length > 0)
                txtkeyword3.Text += "【变量1】";
            else
                MessageBox.Show("变量1没有数据");
        }

        private void button16_Click(object sender, EventArgs e)
        {
            if (txtbl2.Lines.Length > 0)
                txtkeyword3.Text += "【变量2】";
            else
                MessageBox.Show("变量2没有数据");
        }

        private void button15_Click(object sender, EventArgs e)
        {
            if (txtbl3.Lines.Length > 0)
                txtkeyword3.Text += "【变量3】";
            else
                MessageBox.Show("变量3没有数据");
        }

        private void button41_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.ckbHtml.Items.Count; i++)
            {
                this.ckbHtml.SetItemChecked(i, true);
            }
        }

        private void button42_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.ckbHtml.Items.Count; i++)
            {
                if (ckbHtml.GetItemChecked(i))
                {
                    this.ckbHtml.SetItemChecked(i, false);
                }
                else
                {
                    this.ckbHtml.SetItemChecked(i, true);
                }

            }
        }

        private void button43_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.ckbHtml.Items.Count; i++)
            {
                this.ckbHtml.SetItemChecked(i, false);
            }
        }

        private void button47_Click(object sender, EventArgs e)
        {
            if (txtzhubl.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【主变量】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("主变量没有数据");

        }

        private void button48_Click(object sender, EventArgs e)
        {
            if (txtbl1.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【变量1】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("变量1没有数据");

        }

        private void button50_Click(object sender, EventArgs e)
        {
            if (txtbl2.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【变量2】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("变量2没有数据");
        }

        private void button49_Click(object sender, EventArgs e)
        {
            if (txtbl3.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【变量3】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("变量3没有数据");
        }

        private void button51_Click(object sender, EventArgs e)
        {
            if (txtjz.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【句子】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("句子没有数据");
        }

        private void button54_Click(object sender, EventArgs e)
        {
            if (txtdl1.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【段落1】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("段落1没有数据");

        }

        private void button55_Click(object sender, EventArgs e)
        {
            if (txtdl2.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【段落2】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("段落2没有数据");
        }

        private void button56_Click(object sender, EventArgs e)
        {
            if (txtdl3.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【段落3】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("段落3没有数据");
        }

        private void button57_Click(object sender, EventArgs e)
        {
            if (txtdl4.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【段落4】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("段落4没有数据");
        }

        private void button52_Click(object sender, EventArgs e)
        {
            if (txtrandpic.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【随机图片】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("随机图片没有数据");
        }

        private void button53_Click(object sender, EventArgs e)
        {
            if (txtranda.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【随机链接】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("随机链接没有数据");
        }

        private void button58_Click(object sender, EventArgs e)
        {
            txtmbname.Focus();
            this.htmlEditor1.PasteIntoSelection("【年】");
            this.htmlEditor1.Focus();
        }

        private void button59_Click(object sender, EventArgs e)
        {
            txtmbname.Focus();
            this.htmlEditor1.PasteIntoSelection("【月】");
            this.htmlEditor1.Focus();
        }

        private void button60_Click(object sender, EventArgs e)
        {
            txtmbname.Focus();
            this.htmlEditor1.PasteIntoSelection("【日】");
            this.htmlEditor1.Focus();
        }

        private void button98_Click(object sender, EventArgs e)
        {
            this.ckbHtml.Items.Add(txtmbname.Text);
        }

        private void button97_Click(object sender, EventArgs e)
        {
            //保存模版
            string mb = txtmbname.Text.Trim();
            string html = htmlEditor1.BodyInnerHTML;
            AShelp.SaveHtml(html, mb);
            bool ishave = false;
            for (int i = 0; i < ckbHtml.Items.Count; i++)
            {
                if (ckbHtml.GetItemText(ckbHtml.Items[i]) == mb)
                    ishave = true;
            }
            if (!ishave)
            {
                ckbHtml.Items.Add(mb);
            }
            MessageBox.Show("保存成功！~~");
        }

        private void button44_Click(object sender, EventArgs e)
        {
            //新建模版
            //txtmbname.Text = "";
            //htmlEditor1.BodyInnerHTML = "";
            frmHtml f = new frmHtml(this);
            f.ShowDialog();
        }

        private void button45_Click(object sender, EventArgs e)
        {
            //显示第一个选择的模版  
            string temp = "";
            for (int i = 0; i < ckbHtml.Items.Count; i++)
            {
                if (ckbHtml.GetItemChecked(i))
                {
                    temp = ckbHtml.GetItemText(ckbHtml.Items[i]);
                    txtmbname.Text = temp;
                    string html = AShelp.LoadHtml(temp);
                    htmlEditor1.BodyInnerHTML = html;
                    return;

                }
            }
        }

        private void button29_Click(object sender, EventArgs e)
        {
            frmjz f = new frmjz(this);
            f.TopMost = true;
            f.Show();
        }

        private void txtjz_TextChanged(object sender, EventArgs e)
        {
            label29.Text = string.Format("句子库，共有{0}行", txtjz.Lines.Length);
        }

        private void button30_Click(object sender, EventArgs e)
        {
            txtjz.Text = "";
        }

        private void button40_Click(object sender, EventArgs e)
        {
            txtdl4.Text = "";
        }

        private void button34_Click(object sender, EventArgs e)
        {
            txtdl1.Text = "";
        }

        private void button36_Click(object sender, EventArgs e)
        {
            txtdl2.Text = "";
        }

        private void button38_Click(object sender, EventArgs e)
        {
            txtdl3.Text = "";
        }

        private void button33_Click(object sender, EventArgs e)
        {
            string[] s = txtdl1.Lines;
            txtdl1.Lines = AShelp.RandomStrings(s);
        }

        private void button35_Click(object sender, EventArgs e)
        {
            string[] s = txtdl2.Lines;
            txtdl2.Lines = AShelp.RandomStrings(s);
        }

        private void button37_Click(object sender, EventArgs e)
        {
            string[] s = txtdl3.Lines;
            txtdl3.Lines = AShelp.RandomStrings(s);
        }

        private void button39_Click(object sender, EventArgs e)
        {
            string[] s = txtdl4.Lines;
            txtdl4.Lines = AShelp.RandomStrings(s);
        }

        private void button64_Click(object sender, EventArgs e)
        {
            txttishi.Text = "";
        }

        private void btnSCtitle_Click(object sender, EventArgs e)
        {
            string title = txtTitle.Text.Trim();
            List<string> sctitle = new List<string>();
            List<string> sctitle1 = new List<string>();
            string[] city = txtzhubl.Lines;

            int intcity = city.Length;
            string[] bl1 = txtbl1.Lines;
            int intbl1 = bl1.Length;
            string[] bl2 = txtbl2.Lines;
            int intbl2 = bl2.Length;
            string[] bl3 = txtbl3.Lines;
            int intbl3 = bl3.Length;
            sctitle.Add(title);
            bool ishvae = false;
            Random rd = new Random();
            do
            {
                ishvae = false;
                foreach (string st in sctitle)
                {
                    if (st.Contains("【主变量】") && intcity > 0)
                    {
                        Regex r = new Regex("【主变量】");
                        string t = "";
                        foreach (string s in city)
                        {
                            t = r.Replace(st, s, 1);
                            sctitle1.Add(t);
                        }
                        ishvae = true;
                    }
                }
                if (sctitle1.Count > 0)
                {
                    sctitle.Clear();
                    foreach (string s in sctitle1)
                        sctitle.Add(s);
                    sctitle1.Clear();
                }

            } while (ishvae);
            do
            {
                ishvae = false;
                foreach (string st in sctitle)
                {
                    if (st.Contains("【变量1】") && intbl1 > 0)
                    {
                        Regex r = new Regex("【变量1】");
                        string t = "";
                        if (!ckbbl1.Checked)
                            foreach (string s in bl1)
                            {
                                t = r.Replace(st, s, 1);
                                sctitle1.Add(t);
                            }
                        else
                        {

                            t = r.Replace(st, bl1[rd.Next(intbl1)], 1);
                            sctitle1.Add(t);
                        }
                        ishvae = true;
                    }
                }
                if (sctitle1.Count > 0)
                {
                    sctitle.Clear();
                    foreach (string s in sctitle1)
                        sctitle.Add(s);
                    sctitle1.Clear();
                }

            } while (ishvae);
            do
            {
                ishvae = false;
                foreach (string st in sctitle)
                {
                    if (st.Contains("【变量2】") && intbl2 > 0)
                    {
                        Regex r = new Regex("【变量2】");
                        string t = "";
                        if (!ckbbl2.Checked)
                            foreach (string s in bl2)
                            {
                                t = r.Replace(st, s, 1);
                                sctitle1.Add(t);
                            }
                        else
                        {
                            t = r.Replace(st, bl2[rd.Next(intbl2)], 1);
                            sctitle1.Add(t);
                        }
                        ishvae = true;
                    }
                }
                if (sctitle1.Count > 0)
                {
                    sctitle.Clear();
                    foreach (string s in sctitle1)
                        sctitle.Add(s);
                    sctitle1.Clear();
                }

            } while (ishvae);
            do
            {
                ishvae = false;
                foreach (string st in sctitle)
                {
                    if (st.Contains("【变量3】") && intbl3 > 0)
                    {
                        Regex r = new Regex("【变量3】");
                        string t = "";
                        if (!ckbbl3.Checked)
                            foreach (string s in bl3)
                            {
                                t = r.Replace(st, s, 1);
                                sctitle1.Add(t);
                            }
                        else
                        {
                            t = r.Replace(st, bl3[rd.Next(intbl3)], 1);
                            sctitle1.Add(t);
                        }
                        ishvae = true;
                    }
                }
                if (sctitle1.Count > 0)
                {
                    sctitle.Clear();
                    foreach (string s in sctitle1)
                        sctitle.Add(s.Trim());
                    sctitle1.Clear();
                }

            } while (ishvae);
            //sctitle为生成的数据
            if (MessageBox.Show("生成数据" + sctitle.Count + "行！您确定要生成这些数据，如果数据量太大，请选择随机复选框对数据进行重新组合！", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                string[] resultstr = null;
                if (ckbSCDL.Checked)
                {
                    resultstr = AShelp.RandomStrings(sctitle.ToArray());
                }
                else
                {
                    resultstr = sctitle.ToArray();
                }

                foreach (string stitle in resultstr)
                {
                    ListViewItem lvt = new ListViewItem();
                    lvt.Text = stitle;
                    lvt.SubItems.Add("等待发送");
                    lsvdaifa.Items.Add(lvt);
                }
                tabControl5.TabPages[0].Text = string.Format("待发列表({0})", lsvdaifa.Items.Count);
                MessageBox.Show("生成成功！~");

            }
        }

        private void button32_Click(object sender, EventArgs e)
        {
            txtranda.Text = "";
        }

        private void button31_Click(object sender, EventArgs e)
        {
            txtrandpic.Text = "";
        }

        private void txtranda_TextChanged(object sender, EventArgs e)
        {
            label30.Text = string.Format("随机链接，共有{0}行", txtranda.Lines.Length);

        }

        private void txtrandpic_TextChanged(object sender, EventArgs e)
        {
            groupBox11.Text = string.Format("内容图片，共有{0}行", txtrandpic.Lines.Length);
        }

        private void button95_Click(object sender, EventArgs e)
        {
            string checkedname = "";
            int lsindex = -1;
            for (int i = 0; i < this.lsvConfig.Items.Count; i++)
            {
                if (this.lsvConfig.Items[i].Selected)
                {
                    checkedname = this.lsvConfig.Items[i].Text;
                    lsindex = i;
                    break;
                }
            }
            if (checkedname != "")
            {
                if (Myinfo.configname != checkedname)
                {
                    string cname = "";
                    frmInput f = new frmInput();
                    f.TopMost = true;
                    if (f.ShowDialog() == DialogResult.OK)
                    {
                        cname = f.inputName;
                        if (AShelp.ChangeConfigs(checkedname, cname))
                        {
                            this.lsvConfig.Items[lsindex].Text = cname;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("不能修改当前配置");

                }
            }
            else
            {
                MessageBox.Show("请选中一个配置");
            }

        }

        private void button96_Click(object sender, EventArgs e)
        {
            SaveConfig(); ;
            //另存当前配置
            string checkedname = "";
            for (int i = 0; i < this.lsvConfig.Items.Count; i++)
            {
                if (this.lsvConfig.Items[i].Selected)
                {
                    checkedname = this.lsvConfig.Items[i].Text;
                    break;
                }
            }
            if (checkedname != "")
            {
                string cname = "";
                frmInput f = new frmInput();
                f.TopMost = true;
                if (f.ShowDialog() == DialogResult.OK)
                {
                    cname = f.inputName;
                    for (int i = 0; i < this.lsvConfig.Items.Count; i++)
                    {
                        if (this.lsvConfig.Items[i].Text == cname)
                        {
                            MessageBox.Show("已经有一个配置的名字叫" + cname + "，请更换一个新名字！");
                            return;
                        }
                    }
                    if (AShelp.CopyConfigs(checkedname, cname))
                    {
                        ListViewItem lvi = new ListViewItem();
                        lvi.Text = cname;
                        lvi.ImageIndex = 0;
                        this.lsvConfig.Items.Add(lvi);

                    }
                }
            }
            else
            {
                MessageBox.Show("请选中一个配置");
            }
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button94_Click(object sender, EventArgs e)
        {
            string checkedname = "";
            for (int i = 0; i < this.lsvConfig.Items.Count; i++)
            {
                if (this.lsvConfig.Items[i].Selected)
                {
                    checkedname = this.lsvConfig.Items[i].Text;
                    this.lsvConfig.Items[i].ImageIndex = 1;
                }
                else
                {
                    this.lsvConfig.Items[i].ImageIndex = 0;

                }
            }
            if (checkedname != "")
            {
                Myinfo.configname = checkedname;
                lblconfig.Text = "当前配置是：" + checkedname;
                //修改配置文件
                AShelp.SaveConfig(checkedname, "", "", "");
                LoadConfig();
                MessageBox.Show("加载成功！");
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            SaveConfig();
            MessageBox.Show("保存成功！");
        }

        private void SaveConfig()
        {
            List<string> dl = new List<string>();
            if (radioButton4.Checked)
                dl.Add("1");
            else
                dl.Add("0");
            dl.Add(textBox10.Text);
            if (radioButton9.Checked)
                dl.Add("1");
            else
                dl.Add("0");
            dl.Add(textBox11.Text);
            if (radioButton11.Checked)
                dl.Add("1");
            else
                dl.Add("0");
            dl.Add(textBox12.Text);
            if (radioButton13.Checked)
                dl.Add("1");
            else
                dl.Add("0");
            dl.Add(textBox13.Text);
            if (radioButton15.Checked)
                dl.Add("1");
            else
                dl.Add("0");
            dl.Add(textBox14.Text);
            if (radioButton17.Checked)
                dl.Add("1");
            else
                dl.Add("0");
            dl.Add(textBox15.Text);
            if (radioButton21.Checked)
                dl.Add("1");
            else
                dl.Add("0");
            dl.Add(textBox18.Text);
            dl.Add(txtdl5.Text);
            dl.Add(txtdl6.Text);
            AShelp.SaveWZ(dl, "adddl");
            List<string> saveaddid = new List<string>();
            saveaddid.Add(twoid.ToString());
            AShelp.SaveWZ(saveaddid, "addid");
            //分两大块保存1.整体文章管理内容 2.文章的特殊内容（不同的程序设置不一样）
            List<string> savewz = new List<string>();
            savewz.Add(txtzhubl.Text);
            savewz.Add(txtbl1.Text);
            if (ckbbl1.Checked)
                savewz.Add("1");
            else
                savewz.Add("0");
            savewz.Add(txtbl2.Text);
            if (ckbbl2.Checked)
                savewz.Add("1");
            else
                savewz.Add("0");
            savewz.Add(txtbl3.Text);
            if (ckbbl3.Checked)
                savewz.Add("1");
            else
                savewz.Add("0");
            savewz.Add(txtjz.Text);
            savewz.Add(txtranda.Text);
            savewz.Add(txtrandpic.Text);
            savewz.Add(txtdl1.Text);
            if (rbtdl1r.Checked)
                savewz.Add("1");
            else
                savewz.Add("0");
            savewz.Add(txtdl1row.Text);
            savewz.Add(txtdl2.Text);
            if (rbtdl2r.Checked)
                savewz.Add("1");
            else
                savewz.Add("0");
            savewz.Add(txtdl2row.Text);
            savewz.Add(txtdl3.Text);
            if (rbtdl3r.Checked)
                savewz.Add("1");
            else
                savewz.Add("0");
            savewz.Add(txtdl3row.Text);
            savewz.Add(txtdl4.Text);
            if (rbtdl4r.Checked)
                savewz.Add("1");
            else
                savewz.Add("0");
            savewz.Add(txtdl4row.Text);

            savewz.Add(txtTitle.Text);
            if (ckbSCDL.Checked)
                savewz.Add("1");
            else
                savewz.Add("0");
            savewz.Add(txtkeyword1.Text);
            savewz.Add(txtkeyword2.Text);
            savewz.Add(txtkeyword3.Text);
            savewz.Add(txttishi.Text);

            AShelp.SaveWZ(savewz, "WZ");
            List<string> saveadd = new List<string>();
            saveadd.Add(textBox31.Text);
            AShelp.SaveWZ(saveadd, "add");
            List<infos> daifa = new List<infos>();
            foreach (ListViewItem i in this.lsvdaifa.Items)
            {
                infos info = new infos();
                info.title = i.Text;
                info.info = i.SubItems[1].Text;
                daifa.Add(info);
            }
            AShelp.SaveTitle(daifa, "df");

            List<infos> yifa = new List<infos>();
            foreach (ListViewItem i in this.lsvchenggong.Items)
            {
                infos info = new infos();
                info.title = i.Text;
                info.info = i.SubItems[1].Text;
                yifa.Add(info);
            }
            AShelp.SaveTitle(yifa, "cg");

            List<infos> shibai = new List<infos>();
            foreach (ListViewItem i in this.lsvshibai.Items)
            {
                infos info = new infos();
                info.title = i.Text;
                info.info = i.SubItems[1].Text;
                shibai.Add(info);
            }
            AShelp.SaveTitle(shibai, "sb");

            List<string> checkedhtml = new List<string>();
            for (int i = 0; i < ckbHtml.Items.Count; i++)
            {
                if (ckbHtml.GetItemChecked(i))
                {
                    checkedhtml.Add(ckbHtml.GetItemText(ckbHtml.Items[i]));
                }
            }
            AShelp.SaveWZ(checkedhtml, "ckdhtml");



            List<string> teshu = new List<string>();
            teshu.Add(txtSinterval.Text);
            teshu.Add(txtEinterval.Text);
            if (rbpubtbig.Checked)
                teshu.Add("1");
            else
                teshu.Add("0");
            teshu.Add(txtPubnum.Text);
            if (ckbfb1.Checked)
                teshu.Add("1");
            else
                teshu.Add("0");
            if (ckbfb2.Checked)
                teshu.Add("1");
            else
                teshu.Add("0");
            if (ckbfb3.Checked)
                teshu.Add("1");
            else
                teshu.Add("0");
            if (ckbfb4.Checked)
                teshu.Add("1");
            else
                teshu.Add("0");
            if (ckblinkpre.Checked)
                teshu.Add("1");
            else
                teshu.Add("0");
            if (ckbshut.Checked)
                teshu.Add("1");
            else
                teshu.Add("0");
            if (radioButton1.Checked)
                teshu.Add("1");
            else
                teshu.Add("0");
            teshu.Add(txtmini.Text);
            teshu.Add(txtPics.Text);
            teshu.Add(comboBox1.Text.ToString());
            teshu.Add(comboBox2.Text.ToString());
            teshu.Add(cbbone.Text.ToString());
            teshu.Add(cbbtwo.Text.ToString());
            teshu.Add(cbbthree.Text.ToString());
            teshu.Add(comboBox6.Text);
            teshu.Add(textBox1.Text);
            teshu.Add(textBox2.Text);
            teshu.Add(textBox3.Text);
            teshu.Add(textBox4.Text);
            teshu.Add(textBox5.Text);
            teshu.Add(textBox6.Text);
            teshu.Add(textBox7.Text);
            teshu.Add(textBox8.Text);
            teshu.Add(textBox9.Text);
            teshu.Add(comboBox3.Text);
            teshu.Add(comboBox4.Text);
            teshu.Add(comboBox8.Text);
            teshu.Add(comboBox7.Text);
            teshu.Add(comboBox5.Text);
            AShelp.SaveWZ(teshu, "ts");
        }

        private void button61_Click(object sender, EventArgs e)
        {
            ckbfb1.Checked = true;
            ckbfb2.Checked = true;
            ckbfb3.Checked = true;
            ckbfb4.Checked = true;

        }

        private void button66_Click(object sender, EventArgs e)
        {
            AShelp.selectall(lsvdaifa);
        }

        private void button67_Click(object sender, EventArgs e)
        {
            AShelp.reversselect(lsvdaifa);
        }

        private void button68_Click(object sender, EventArgs e)
        {
            AShelp.delselect(lsvdaifa);
            UpdateTabNum();
        }

        private void button69_Click(object sender, EventArgs e)
        {
            lsvdaifa.Items.Clear();
            UpdateTabNum();
        }

        private void button71_Click(object sender, EventArgs e)
        {
            List<string> data = new List<string>();
            for (int i = 0; i < lsvdaifa.Items.Count; i++)
            {
                data.Add(lsvdaifa.Items[i].Text);
            }
            string[] newdata = AShelp.RandomStrings(data.ToArray());

            lsvdaifa.Items.Clear();
            foreach (string s in newdata)
            {
                ListViewItem lsv = new ListViewItem();
                lsv.Text = s;
                lsv.SubItems.Add("等待发送");
                lsvdaifa.Items.Add(lsv);
            }
        }

        private void button70_Click(object sender, EventArgs e)
        {
            //导出数据
            saveFileDialog1.Filter = "文本文件(*.txt)|*.txt";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string file = saveFileDialog1.FileName;
                List<string> list = AShelp.getselecttext(lsvdaifa);
                //string txt = string.Join("||", list.ToArray());
                string txt = string.Join("\r\n", list.ToArray());
                AShelp.SaveTXT(txt, file);
                MessageBox.Show("保存成功！");
            }
        }

        private void button79_Click(object sender, EventArgs e)
        {
            AShelp.selectall(lsvchenggong);
        }

        private void button78_Click(object sender, EventArgs e)
        {
            AShelp.reversselect(lsvchenggong);

        }

        private void button77_Click(object sender, EventArgs e)
        {
            AShelp.delselect(lsvchenggong);
            UpdateTabNum();
        }

        private void button76_Click(object sender, EventArgs e)
        {
            lsvchenggong.Items.Clear();
            UpdateTabNum();
        }

        private void button75_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < lsvchenggong.Items.Count; i++)
            {
                if (lsvchenggong.Items[i].Checked)
                {
                    ListViewItem lsv = new ListViewItem();
                    lsv.Text = lsvchenggong.Items[i].Text;
                    lsv.SubItems.Add("来自成功列表");
                    lsvchenggong.Items.RemoveAt(i);
                    lsvdaifa.Items.Add(lsv);
                    i--;
                }
            }
            UpdateTabNum();
        }

        private void button86_Click(object sender, EventArgs e)
        {
            AShelp.selectall(lsvshibai);
        }

        private void button85_Click(object sender, EventArgs e)
        {
            AShelp.reversselect(lsvshibai);
        }

        private void button84_Click(object sender, EventArgs e)
        {
            AShelp.delselect(lsvshibai);
            UpdateTabNum();
        }

        private void button83_Click(object sender, EventArgs e)
        {
            lsvshibai.Items.Clear();
            UpdateTabNum();
        }

        private void button82_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < lsvshibai.Items.Count; i++)
            {
                if (lsvshibai.Items[i].Checked)
                {
                    ListViewItem lsv = new ListViewItem();
                    lsv.Text = lsvshibai.Items[i].Text;
                    lsv.SubItems.Add("来自失败列表");
                    lsvshibai.Items.RemoveAt(i);
                    lsvdaifa.Items.Add(lsv);
                    i--;
                }
            }
            UpdateTabNum();

        }

        private void button72_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "文本文件(*.txt)|*.txt";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string file = openFileDialog1.FileName;
                string txt = AShelp.LoadTXT(file);
                //string[] titles = txt.Split(


                MessageBox.Show("导入成功！");
            }
        }

        private void btnPub_Click(object sender, EventArgs e)
        {
            if (myhttp.islogin == "OK")
            {

                ThreadStart start = null;

                if (start == null)
                {
                    start = pubtitle;
                }
                if (isstoppub)
                {
                    if (t != null)
                        t.Abort();
                    t = new Thread(start);
                    t.IsBackground = true;
                    t.Start();
                    isstoppub = false;
                }
                else
                {
                    MessageBox.Show("正在发布，请停止后再开始！");

                }

            }
            else
            {
                MessageBox.Show("请登录后再操作！");
            }

        }
        private void pubtitle()
        {
            bool fb1 = true, fb2 = true, fb3 = true, fb4 = true;
            bool cfb1 = true, cfb2 = true, cfb3 = true, cfb4 = true;
            cfb1 = ckbfb1.Checked;
            cfb2 = ckbfb2.Checked;
            cfb3 = ckbfb3.Checked;
            cfb4 = ckbfb4.Checked;
            int stime = 30, etime = 40, sleeptime = 30;
            int nums = 0;
            bool islimited = false;
            if (rbpubtnum.Checked)
            {
                islimited = true;
                int.TryParse(txtPubnum.Text.Trim(), out nums);
            }
            string title = "";
            string content = "";
            string managerurl = "";
            string errormsg = "";
            string lasterror = "";
            string baidumsg = "";
            string tempurl;
            Random rnd = new Random();
            List<string> htmllist = new List<string>();
            for (int j = 0; j < this.ckbHtml.Items.Count; j++)
            {
                if (ckbHtml.GetItemChecked(j))
                {
                    htmllist.Add(ckbHtml.GetItemText(ckbHtml.Items[j]));
                }
            }
            if (htmllist.Count < 1)
            {
                MessageBox.Show("请选择要使用的文章内容模版列表！");
                tabControl1.TabPages[3].Select();
                return;
            }
            int.TryParse(txtSinterval.Text, out stime);
            int.TryParse(txtEinterval.Text, out etime);
            StringBuilder strpost = new StringBuilder();
            StringBuilder strtemp = new StringBuilder();
            string __VIEWSTATE = "";
            string sTypeList = "供应", newsType = "企业动态", txtgytitle = "", sKeyword1 = "", sKeyword2 = "", sKeyword3 = "", sTimelList = "一个月", hidflidlist = "", hidflnamelist = "";
            string coneid = "", ctwoid = "", cthreeid = "", cid = "", hidcategory = "0", hidsubcategory = "0", newscategory = "0", sUnitTB = "", sPriceTB = "0", sNumTB = "";
            string sLeastNumTB = "", sBrandTB = "", sPackTB = "", sSpecTB = "", sTransitTB = "", sDeliveryTB = "", txtgydesc = "", hidimg1 = "", hidimgb1 = "", hidimg2 = "", hidimgb2 = "", hidimg3 = "", hidimgb3 = "", sReleaseButton = "发布";
            string hidtitlc = "", hidpic = "", hiddesc = "", hidtltIc = "", hidlitlc = "", hidtitle = "";
            HttpResult r = null;
            if (cbbone.SelectedValue != null)
                coneid = cbbone.SelectedValue.ToString();
            if (cbbtwo.SelectedValue != null)
                ctwoid = cbbtwo.SelectedValue.ToString();
            if (twoid == 0) ctwoid = "0";
            if (cbbthree.SelectedValue != null)
                cthreeid = cbbthree.SelectedValue.ToString();
            hidflidlist = coneid + "|" + ctwoid + "|" + cthreeid;
            hidflnamelist = cbbone.Text.ToString() + "-" + cbbtwo.Text.ToString() + "-" + cbbthree.Text.ToString();
            if (comboBox1.SelectedValue != null)
                if (comboBox1.SelectedValue.ToString() != "0")
                {
                    hidcategory = comboBox1.SelectedValue.ToString();
                }
            if (comboBox2.SelectedValue != null)
                if (comboBox2.SelectedValue.ToString() != "0")
                {
                    hidsubcategory = comboBox2.SelectedValue.ToString();
                }
            if (comboBox8.SelectedValue != null)
                if (comboBox8.SelectedValue.ToString() != "0")
                {
                    newscategory = comboBox8.SelectedValue.ToString();
                }
            sUnitTB = textBox2.Text.Trim();
            int price = 0;
            int.TryParse(textBox1.Text.Trim(), out price);
            sPriceTB = price.ToString();
            sNumTB = textBox4.Text.Trim();
            sLeastNumTB = textBox3.Text.Trim();
            sBrandTB = textBox6.Text.Trim();
            sPackTB = textBox9.Text.Trim();
            sSpecTB = textBox5.Text.Trim();
            sTransitTB = textBox8.Text.Trim();
            sDeliveryTB = textBox7.Text.Trim();
            cid = myhttp.myid;
            string[] pics = AShelp.delspaceStrings(txtPics.Lines);
            if (pics.Length < 1)
            {
                MessageBox.Show("没有图片可用！");
                return;
            }
            //公共信息
            strpost.AppendFormat("hidflidlist={0}&", hidflidlist);
            strpost.AppendFormat("hidflnamelist={0}&", hidflnamelist);
            strpost.AppendFormat("coneid={0}&", coneid);
            strpost.AppendFormat("ctwoid={0}&", ctwoid);
            strpost.AppendFormat("cthreeid={0}&", cthreeid);
            strpost.AppendFormat("cid={0}&", cid);

            string pubmsell = "http://b2b.sg560.com/member/sell/mSell,overpass" + myhttp.sgid + ".html";
            //HttpResult r1 = myhttp.HttpGet(managerurl, "");
            //tempurl = myhttp.GetHtmlahrefLike(r1.Html.ToString(), "/member/sell/mSell,overpass");
            //myhttp.sgid = myhttp.getmysgid(tempurl, "overpass");
            string httppub = "http://b2b.sg560.com/member/sell/SellTosr" + myhttp.sgid + ".html";
            string url = "http://b2b.sg560.com/member/sell/SellTosr" + myhttp.sgid + ".html?sgfid=" + myhttp.sgid;
            string httppubpro = "http://b2b.sg560.com/member/Product/Protosr" + myhttp.sgid + ".html";
            string urlpro = "http://b2b.sg560.com/member/Product/Protosr" + myhttp.sgid + ".html?sgfid=" + myhttp.sgid;
            string httppubbuy = "http://b2b.sg560.com/member/buy/BuyInfo" + myhttp.sgid + ".html";
            string urlbuy = "http://b2b.sg560.com/member/buy/BuyInfo" + myhttp.sgid + ".html?sgfid=" + myhttp.sgid;
            string httppubnew = "http://b2b.sg560.com/member/shop/ComNewsxy" + myhttp.sgid + ".html";
            string urlnew = "http://b2b.sg560.com/member/shop/ComNewsxy" + myhttp.sgid + ".html?sgfid=" + myhttp.sgid;
            string prehtml = "";
            int havecont = 0;
            foreach (System.Windows.Forms.ListViewItem lvi in lsvdaifa.Items)  //选中项遍历
            {
                havecont = 0;
                havecont = lsvdaifa.Items.Count;
                if (lvi.SubItems[1].Text.Contains("等待时间还有"))
                {
                    isstarttime = false;
                }
                lvi.SubItems[1].Text = "正在发布";
                lsvdaifa.Refresh();
                if (!isstoppub)//停止
                {
                    if (islimited)//数量限制
                    {
                        if (nums > 0)
                        {
                            nums--;
                        }
                        else
                        {
                            txttishi.Text += "设定的信息条数已发完！";
                            Thread.CurrentThread.Abort();
                        }
                    }

                    if (ckblinkpre.Checked)
                    {
                        if (titleurl != "")
                        {
                            prehtml = "<br/><a href='" + titleurl + "'>上一篇文章(" + titleurl + ")</a>";
                        }
                    }
                    else
                    {
                        prehtml = "";
                    }

                    try
                    {

                        #region 发布供应
                        if (cfb1)
                        {
                            if (fb1)
                            {
                                title = lvi.Text;
                                txttishi.Text += "当前正在发布的文章为:" + title + "。\r\n";
                                txtgytitle = title.Trim();
                                sKeyword1 = ReplaceKeywords(txtkeyword1.Text);
                                sKeyword2 = ReplaceKeywords(txtkeyword2.Text);
                                sKeyword3 = ReplaceKeywords(txtkeyword3.Text);
                                if (sKeyword1 == sKeyword2 && sKeyword2 == sKeyword3 && sKeyword3 == "")
                                {
                                    if (txtgytitle.Length > 8)
                                        sKeyword1 = txtgytitle.Substring(0, 8);
                                    else
                                        sKeyword1 = txtgytitle;
                                    //txttishi.Text += "发布的文章关键字不能为空！。\r\n";
                                    //if (t != null)
                                    //    t.Abort();
                                    //return;
                                }
                                if (sKeyword1.Length > 8) sKeyword1 = sKeyword1.Substring(0, 8);
                                if (sKeyword2.Length > 8) sKeyword2 = sKeyword2.Substring(0, 8);
                                if (sKeyword3.Length > 8) sKeyword3 = sKeyword3.Substring(0, 8);
                                content = AShelp.LoadHtml(htmllist[rnd.Next(htmllist.Count)]);
                                content = ReplaceHTMLWZ(content, title);
                                if (prehtml != "")
                                    txtgydesc = content + prehtml;
                                else
                                    txtgydesc = content;
                                if (txtPics.Lines.Length > 0)
                                {
                                    hidimgb1 = pics[rnd.Next(pics.Length)];
                                    hidimg1 = pics[rnd.Next(pics.Length)];
                                    hidimgb2 = pics[rnd.Next(pics.Length)];
                                    hidimg2 = pics[rnd.Next(pics.Length)];
                                    hidimgb3 = pics[rnd.Next(pics.Length)];
                                    hidimg3 = pics[rnd.Next(pics.Length)];
                                }
                                strtemp.Remove(0, strtemp.Length);

                                r = myhttp.HttpGet("http://b2b.sg560.com/member/sell/SellTosr" + myhttp.sgid + ".html", "");
                                hidtitlc = myhttp.GetHtmlID(r.Html.ToString(), "input", "hidtitlc");
                                hidlitlc = myhttp.GetHtmlID(r.Html.ToString(), "input", "hidlitlc");
                                hidpic = myhttp.GetHtmlID(r.Html.ToString(), "input", "hidpic");
                                hiddesc = myhttp.GetHtmlID(r.Html.ToString(), "input", "hiddesc");
                                __VIEWSTATE = myhttp.GetHtmlID(r.Html.ToString(), "input", "__VIEWSTATE");
                                hidtitle = myhttp.GetHtmlID(r.Html.ToString(), "input", "hidtitle");
                                strtemp.AppendFormat("__VIEWSTATE={0}&", Uri.EscapeDataString(__VIEWSTATE));
                                strtemp.AppendFormat("__SCROLLPOSITIONX={0}&", "0");
                                strtemp.AppendFormat("__SCROLLPOSITIONY={0}&", "999");
                                strtemp.AppendFormat("__EVENTTARGET={0}&", "");
                                strtemp.AppendFormat("__EVENTARGUMENT={0}&", "");
                                if (comboBox3.SelectedItem != null)
                                    sTypeList = comboBox3.SelectedItem.ToString();
                                if (comboBox6.SelectedItem != null)
                                    sTimelList = comboBox6.SelectedItem.ToString();
                                strtemp.AppendFormat("sTypeList={0}&", sTypeList);
                                strtemp.AppendFormat("txtgytitle={0}&", txtgytitle);
                                strtemp.AppendFormat("sKeyword1={0}&", sKeyword1);
                                strtemp.AppendFormat("sKeyword2={0}&", sKeyword2);
                                strtemp.AppendFormat("sKeyword3={0}&", sKeyword3);
                                strtemp.AppendFormat("sTimelList={0}&", sTimelList);
                                strtemp.Append(strpost.ToString());
                                strtemp.AppendFormat("hidcategory={0}&", hidcategory);
                                strtemp.AppendFormat("hidsubcategory={0}&", hidsubcategory);
                                strtemp.AppendFormat("sUnitTB={0}&", sUnitTB);
                                strtemp.AppendFormat("sPriceTB={0}&", sPriceTB);
                                strtemp.AppendFormat("sNumTB={0}&", sNumTB);
                                strtemp.AppendFormat("sLeastNumTB={0}&", sLeastNumTB);
                                strtemp.AppendFormat("sBrandTB={0}&", sBrandTB);
                                strtemp.AppendFormat("sPackTB={0}&", sPackTB);
                                strtemp.AppendFormat("sSpecTB={0}&", sSpecTB);
                                strtemp.AppendFormat("sTransitTB={0}&", sTransitTB);
                                strtemp.AppendFormat("sDeliveryTB={0}&", sDeliveryTB);
                                strtemp.AppendFormat("txtgydesc={0}&", txtgydesc);
                                strtemp.AppendFormat("hidimg1={0}&", hidimg1);
                                strtemp.AppendFormat("hidimgb1={0}&", hidimgb1);
                                //strtemp.AppendFormat("hidimgb1={0}&", "");
                                strtemp.AppendFormat("sReleaseButton={0}&", sReleaseButton);

                                strtemp.AppendFormat("hidtitlc={0}&", hidtitlc);
                                strtemp.AppendFormat("hidlitlc={0}&", Uri.EscapeDataString(hidlitlc));

                                strtemp.AppendFormat("hidpic={0}&", Uri.EscapeDataString(hidpic));
                                strtemp.AppendFormat("hiddesc={0}&", Uri.EscapeDataString(hiddesc));
                                strtemp.AppendFormat("hidtitle={0}", hidtitle);

                                //"__SCROLLPOSITIONX" = "0"
                                //"__SCROLLPOSITIONY" = "999"
                                //"__EVENTTARGET" = ""
                                //"__EVENTARGUMENT" = ""


                                //组织发布内容
                                HttpResult hr = myhttp.PubTitleByte(url, strtemp.ToString());
                                // HttpResult hr = myhttp.PubTitle(url, strtemp.ToString());
                                string html = hr.Html;
                                if (html.Contains("su(1)"))
                                {
                                    //发布成功。
                                    txttishi.Text += "标题:" + title + "发布成功。\r\n";
                                    managerurl = myhttp.GetHtmlValue(html, "a", "cur", "class", "href");
                                    if (!managerurl.Contains("http//"))
                                    {
                                        managerurl = "http://b2b.sg560.com/member/sell/" + managerurl;

                                    }
                                    r = myhttp.HttpGet(managerurl, "");
                                    titleurl = myhttp.GetHtmlahref(r.Html.ToString(), txtgytitle);
                                    tempurl = myhttp.GetHtmlahrefLike(r.Html.ToString(), "/member/sell/mSell,overpass");
                                    //myhttp.sgid = myhttp.getmysgid(tempurl, "overpass");
                                    lvi.SubItems[1].Text = titleurl;
                                    //lsvdaifa.Items.RemoveAt(lvi.Index); // 按索引移除 
                                    lsvdaifa.Items.Remove(lvi);
                                    lsvchenggong.Items.Add(lvi.Clone() as ListViewItem);
                                    UpdateTabNum();
                                    txttishi.Text += "链接:" + titleurl + "\r\n";
                                    //随机等待0秒
                                    //ping baidu                                    
                                    baidumsg = myhttp.postToPing(titleurl);
                                    txttishi.Text += "链接ping给百度完毕\r\n";
                                    //等待秒数
                                    if (havecont > 1)
                                    {
                                        sleeptime = stime + rnd.Next(etime - stime);
                                        txttishi.Text += "随机等待" + sleeptime + "秒。\r\n";
                                        waitsecond = sleeptime;
                                        isstarttime = true;
                                        Thread.Sleep(sleeptime * 1000);


                                    }
                                    else
                                    {
                                        txttishi.Text += "最后一条数据发送完成！\r\n";
                                    }
                                    lasterror = "";
                                    continue;//再发送本栏目信息
                                }
                                else
                                {
                                    if (html.Length > 0)
                                    {
                                        if (html.Contains("alert"))
                                        {
                                            string temp = html.Substring(html.LastIndexOf("alert") + 7);
                                            errormsg = temp.Substring(0, temp.IndexOf(")") - 1);

                                            if (errormsg.Contains("已经发布了"))
                                            {
                                                txttishi.Text += "提示信息：本栏发布数量已完成！" + errormsg + "\r\n";
                                                fb1 = false;
                                            }
                                            else
                                            {
                                                txttishi.Text += "出错:" + errormsg + "\r\n";
                                                lvi.SubItems[1].Text = errormsg;
                                                lsvdaifa.Items.RemoveAt(lvi.Index); // 按索引移除 
                                                lsvshibai.Items.Add(lvi.Clone() as ListViewItem);
                                                UpdateTabNum();
                                                if (lasterror != errormsg)
                                                {
                                                    lasterror = errormsg;
                                                    continue;
                                                }
                                                else
                                                {
                                                    lasterror = "";
                                                    txttishi.Text += "重复出错，已自动停止！\r\n";
                                                    isstoppub = true;
                                                    if (t != null)
                                                        t.Abort();
                                                    return;
                                                }

                                            }
                                        }
                                        else if (html.Contains("Object moved"))
                                        {
                                            txttishi.Text += "出错:用户已退出系统，请重新登录！\r\n";
                                            isstoppub = true;
                                            if (t != null)
                                                t.Abort();
                                            return;

                                        }
                                        else if (html.Contains("无法解析此远程名称")|| html.Contains("无法连接到远程服务器")|| html.Contains("remote name could not be resolved"))
                                        {
                                            lvi.SubItems[1].Text = "网络无法连接！";
                                            lsvdaifa.Items.Remove(lvi); // 按索引移除 
                                            lsvshibai.Items.Add(lvi.Clone() as ListViewItem);
                                            txttishi.Text += "网络无法连接！\r\n";
                                            sleeptime = stime + rnd.Next(etime - stime);
                                            txttishi.Text += "随机等待" + sleeptime + "秒。\r\n";
                                            waitsecond = sleeptime;
                                            isstarttime = true;
                                            Thread.Sleep(sleeptime * 1000);
                                            continue;//再发送本栏目信息
                                        }
                                        else
                                        {
                                            txttishi.Text += "出错:情况未知，请查看日志！\r\n";
                                            AShelp.SaveTXT(html, Application.StartupPath + "\\错误记录\\" + title + ".txt");

                                        }

                                    }
                                    else
                                    {
                                        txttishi.Text += "出错:没有收到响应！\r\n";

                                    }
                                }
                            }
                        }
                        #endregion

                        #region 产品发布
                        if (cfb2)
                        {
                            if (fb2)
                            {
                                title = lvi.Text;
                                txttishi.Text += "当前正在发布的文章为:" + title + "。\r\n";
                                txtgytitle = title.Trim();
                                sKeyword1 = ReplaceKeywords(txtkeyword1.Text);
                                sKeyword2 = ReplaceKeywords(txtkeyword2.Text);
                                sKeyword3 = ReplaceKeywords(txtkeyword3.Text);
                                if (sKeyword1 == sKeyword2 && sKeyword2 == sKeyword3 && sKeyword3 == "")
                                {
                                    if (txtgytitle.Length > 8)
                                        sKeyword1 = txtgytitle.Substring(0, 8);
                                    else
                                        sKeyword1 = txtgytitle;
                                    //txttishi.Text += "发布的文章关键字不能为空！。\r\n";
                                    //if (t != null)
                                    //    t.Abort();
                                    //return;
                                }
                                if (sKeyword1.Length > 8) sKeyword1 = sKeyword1.Substring(0, 8);
                                if (sKeyword2.Length > 8) sKeyword2 = sKeyword2.Substring(0, 8);
                                if (sKeyword3.Length > 8) sKeyword3 = sKeyword3.Substring(0, 8);
                                content = AShelp.LoadHtml(htmllist[rnd.Next(htmllist.Count)]);
                                content = ReplaceHTMLWZ(content, title);
                                if (prehtml != "")
                                    txtgydesc = content + prehtml;
                                else
                                    txtgydesc = content;
                                if (txtPics.Lines.Length > 0)
                                {
                                    hidimgb1 = pics[rnd.Next(pics.Length)];
                                    hidimg1 = pics[rnd.Next(pics.Length)];
                                    hidimgb2 = pics[rnd.Next(pics.Length)];
                                    hidimg2 = pics[rnd.Next(pics.Length)];
                                    hidimgb3 = pics[rnd.Next(pics.Length)];
                                    hidimg3 = pics[rnd.Next(pics.Length)];
                                }
                                strtemp.Remove(0, strtemp.Length);
                                strtemp.Append(strpost.ToString());
                                r = myhttp.HttpGet(httppubpro, "");
                                hidtitlc = myhttp.GetHtmlID(r.Html.ToString(), "input", "hidlitIc");
                                hidpic = myhttp.GetHtmlID(r.Html.ToString(), "input", "hidpic");
                                hiddesc = myhttp.GetHtmlID(r.Html.ToString(), "input", "hiddesc");
                                __VIEWSTATE = myhttp.GetHtmlID(r.Html.ToString(), "input", "__VIEWSTATE");
                                strtemp.AppendFormat("hidlitIc={0}&", Uri.EscapeDataString(hidtitlc));
                                //hidtltIc
                                strtemp.AppendFormat("hidtltIc={0}&", "");
                                strtemp.AppendFormat("hidpic={0}&", Uri.EscapeDataString(hidpic));
                                strtemp.AppendFormat("hiddesc={0}&", Uri.EscapeDataString(hiddesc));
                                strtemp.AppendFormat("__VIEWSTATE={0}&", Uri.EscapeDataString(__VIEWSTATE));
                                strtemp.AppendFormat("pReleaseButton={0}&", sReleaseButton);
                                strtemp.AppendFormat("txtcptitle={0}&", txtgytitle);
                                strtemp.AppendFormat("pTypeTB={0}&", sSpecTB);
                                strtemp.AppendFormat("pBrandTB={0}&", sBrandTB);
                                strtemp.AppendFormat("pKeyword1TB={0}&", sKeyword1);
                                strtemp.AppendFormat("pKeyword2TB={0}&", sKeyword2);
                                strtemp.AppendFormat("pKeyword3TB={0}&", sKeyword3);
                                strtemp.AppendFormat("pUnitTB={0}&", sUnitTB);
                                strtemp.AppendFormat("pPriceTB={0}&", sPriceTB);
                                strtemp.AppendFormat("pAmountTB={0}&", sNumTB);
                                strtemp.AppendFormat("pLeastNumTB={0}&", sLeastNumTB);
                                strtemp.AppendFormat("pAccountTB={0}&", sDeliveryTB);
                                strtemp.AppendFormat("txtcpdesc={0}&", txtgydesc);
                                strtemp.AppendFormat("hidimg1={0}&", hidimg1);
                                strtemp.AppendFormat("hidimgb1={0}&", hidimgb1);
                                strtemp.AppendFormat("hidimg2={0}&", hidimg2);
                                strtemp.AppendFormat("hidimgb2={0}&", hidimgb2);
                                strtemp.AppendFormat("hidimg3={0}&", hidimg3);
                                strtemp.AppendFormat("hidimgb3={0}&", hidimgb3);
                                strtemp.AppendFormat("hidfile={0}&", "");
                                strtemp.AppendFormat("fileNameTB={0}", "");
                                HttpResult hr = myhttp.PubTitle(urlpro, strtemp.ToString());
                                string html = hr.Html;
                                if (html.Contains("su(1)"))
                                {
                                    //发布成功。
                                    txttishi.Text += "标题:" + title + "发布成功。\r\n";
                                    managerurl = myhttp.GetHtmlValue(html, "a", "cur", "class", "href");
                                    if (!managerurl.Contains("http//"))
                                    {
                                        managerurl = "http://b2b.sg560.com/member/Product/" + managerurl;

                                    }
                                    r = myhttp.HttpGet(managerurl, "");
                                    titleurl = myhttp.GetHtmlahref(r.Html.ToString(), txtgytitle);

                                    lvi.SubItems[1].Text = titleurl;
                                    lsvdaifa.Items.RemoveAt(lvi.Index); // 按索引移除 
                                    lsvchenggong.Items.Add(lvi.Clone() as ListViewItem);
                                    UpdateTabNum();
                                    txttishi.Text += "链接:" + titleurl + "\r\n";
                                    //随机等待0秒
                                    //ping baidu                                    
                                    baidumsg = myhttp.postToPing(titleurl);
                                    txttishi.Text += "链接ping给百度完毕\r\n";
                                    //等待秒数
                                    if (havecont > 1)
                                    {
                                        sleeptime = stime + rnd.Next(etime - stime);
                                        txttishi.Text += "随机等待" + sleeptime + "秒。\r\n";
                                        waitsecond = sleeptime;
                                        isstarttime = true;
                                        Thread.Sleep(sleeptime * 1000);

                                    }
                                    else
                                    {
                                        txttishi.Text += "最后一条数据发送完成！\r\n";
                                    }
                                    lasterror = "";
                                    continue;//再发送本栏目信息
                                }
                                else
                                {
                                    if (html.Length > 0)
                                    {
                                        if (html.Contains("alert"))
                                        {
                                            string temp = html.Substring(html.LastIndexOf("alert") + 7);
                                            errormsg = temp.Substring(0, temp.IndexOf(")") - 1);
                                            if (errormsg.Contains("已经发布了"))
                                            {
                                                txttishi.Text += "提示信息：本栏发布数量已完成！" + errormsg + "\r\n";
                                                fb2 = false;
                                            }
                                            else
                                            {
                                                txttishi.Text += "出错:" + errormsg + "\r\n";
                                                lvi.SubItems[1].Text = errormsg;
                                                lsvdaifa.Items.RemoveAt(lvi.Index); // 按索引移除 
                                                lsvshibai.Items.Add(lvi.Clone() as ListViewItem);
                                                UpdateTabNum();
                                                if (lasterror != errormsg)
                                                {
                                                    lasterror = errormsg;
                                                    continue;
                                                }
                                                else
                                                {
                                                    lasterror = "";
                                                    txttishi.Text += "重复出错，已自动停止！\r\n";
                                                    isstoppub = true;
                                                    if (t != null)
                                                        t.Abort();
                                                    return;
                                                }
                                            }
                                        }
                                        else if (html.Contains("Object moved"))
                                        {
                                            txttishi.Text += "出错:用户已退出系统，请重新登录！\r\n";
                                            isstoppub = true;
                                            if (t != null)
                                                t.Abort();
                                            return;

                                        }
                                        else if (html.Contains("无法解析此远程名称") || html.Contains("无法连接到远程服务器") || html.Contains("remote name could not be resolved"))
                                        {
                                            lvi.SubItems[1].Text = "网络无法连接！";
                                            lsvdaifa.Items.Remove(lvi); // 按索引移除 
                                            lsvshibai.Items.Add(lvi.Clone() as ListViewItem);
                                            txttishi.Text += "网络无法连接！\r\n";
                                            sleeptime = stime + rnd.Next(etime - stime);
                                            txttishi.Text += "随机等待" + sleeptime + "秒。\r\n";
                                            waitsecond = sleeptime;
                                            isstarttime = true;
                                            Thread.Sleep(sleeptime * 1000);
                                            continue;//再发送本栏目信息
                                        }
                                        else
                                        {
                                            txttishi.Text += "出错:情况未知，请查看日志！\r\n";
                                            AShelp.SaveTXT(html, Application.StartupPath + "\\错误记录\\" + title + ".txt");

                                        }
                                    }
                                    else
                                    {
                                        txttishi.Text += "出错:没有收到响应！\r\n";

                                    }
                                }
                            }
                        }
                        #endregion

                        #region 求购发布
                        if (cfb4)
                        {
                            if (fb4)
                            {
                                title = lvi.Text;
                                txttishi.Text += "当前正在发布的文章为:" + title + "。\r\n";
                                txtgytitle = title.Trim();
                                sKeyword1 = ReplaceKeywords(txtkeyword1.Text);
                                sKeyword2 = ReplaceKeywords(txtkeyword2.Text);
                                sKeyword3 = ReplaceKeywords(txtkeyword3.Text);
                                if (sKeyword1 == sKeyword2 && sKeyword2 == sKeyword3 && sKeyword3 == "")
                                {
                                    if (txtgytitle.Length > 8)
                                        sKeyword1 = txtgytitle.Substring(0, 8);
                                    else
                                        sKeyword1 = txtgytitle;
                                    //txttishi.Text += "发布的文章关键字不能为空！。\r\n";
                                    //if (t != null)
                                    //    t.Abort();
                                    //return;
                                }
                                if (sKeyword1.Length > 8) sKeyword1 = sKeyword1.Substring(0, 8);
                                if (sKeyword2.Length > 8) sKeyword2 = sKeyword2.Substring(0, 8);
                                if (sKeyword3.Length > 8) sKeyword3 = sKeyword3.Substring(0, 8);
                                content = AShelp.LoadHtml(htmllist[rnd.Next(htmllist.Count)]);
                                content = ReplaceHTMLWZ(content, title);
                                if (prehtml != "")
                                    txtgydesc = content + prehtml;
                                else
                                    txtgydesc = content;
                                if (txtPics.Lines.Length > 0)
                                {
                                    hidimgb1 = pics[rnd.Next(pics.Length)];
                                    hidimg1 = pics[rnd.Next(pics.Length)];
                                    hidimgb2 = pics[rnd.Next(pics.Length)];
                                    hidimg2 = pics[rnd.Next(pics.Length)];
                                    hidimgb3 = pics[rnd.Next(pics.Length)];
                                    hidimg3 = pics[rnd.Next(pics.Length)];
                                }
                                strtemp.Remove(0, strtemp.Length);
                                strtemp.Append(strpost.ToString());
                                r = myhttp.HttpGet(httppubbuy, "");
                                __VIEWSTATE = myhttp.GetHtmlID(r.Html.ToString(), "input", "__VIEWSTATE");
                                strtemp.AppendFormat("hidtitlc={0}&", Uri.EscapeDataString(hidtitlc));
                                strtemp.AppendFormat("hidpic={0}&", Uri.EscapeDataString(hidpic));
                                strtemp.AppendFormat("hiddesc={0}&", Uri.EscapeDataString(hiddesc));
                                strtemp.AppendFormat("__VIEWSTATE={0}&", Uri.EscapeDataString(__VIEWSTATE));
                                if (comboBox4.Text != "")
                                    sTypeList = comboBox4.Text.ToString();
                                else
                                    sTypeList = "求购";
                                if (comboBox5.SelectedItem != null)
                                    sTimelList = comboBox5.SelectedItem.ToString();
                                else
                                    sTimelList = "10天";
                                strtemp.AppendFormat("bTypeList={0}&", sTypeList);
                                strtemp.AppendFormat("bTimelList={0}&", sTimelList);
                                strtemp.AppendFormat("txtqgtitle={0}&", txtgytitle);
                                strtemp.AppendFormat("bReleaseButton={0}&", sReleaseButton);
                                strtemp.AppendFormat("bKeyword1={0}&", sKeyword1);
                                strtemp.AppendFormat("bKeyword2={0}&", sKeyword2);
                                strtemp.AppendFormat("bKeyword3={0}&", sKeyword3);
                                strtemp.AppendFormat("bUnitTB={0}&", sUnitTB);
                                strtemp.AppendFormat("bPriceTB={0}&", sPriceTB);
                                strtemp.AppendFormat("bNumTB={0}&", sNumTB);
                                strtemp.AppendFormat("bBrandTB={0}&", sBrandTB);
                                strtemp.AppendFormat("bPackTB={0}&", sPackTB);
                                strtemp.AppendFormat("bSpecTB={0}&", sSpecTB);
                                strtemp.AppendFormat("bTransitTB={0}&", sTransitTB);
                                strtemp.AppendFormat("bDeliveryTB={0}&", sDeliveryTB);
                                strtemp.AppendFormat("txtqgdesc={0}&", txtgydesc);
                                strtemp.AppendFormat("hidimg1={0}&", hidimg1);
                                strtemp.AppendFormat("hidimgb1={0}&", hidimgb1);
                                HttpResult hr = myhttp.PubTitle(urlbuy, strtemp.ToString());
                                string html = hr.Html;
                                if (html.Contains("su(1)") || html.Contains("su(2)"))
                                {
                                    //发布成功。
                                    txttishi.Text += "标题:" + title + "发布成功。\r\n";
                                    managerurl = myhttp.GetHtmlValue(html, "a", "cur", "class", "href");
                                    if (!managerurl.Contains("http//"))
                                    {
                                        managerurl = "http://b2b.sg560.com/member/buy/" + managerurl;

                                    }
                                    r = myhttp.HttpGet(managerurl, "");
                                    titleurl = myhttp.GetHtmlahref(r.Html.ToString(), txtgytitle);
                                    if (titleurl == "")
                                    {
                                        //http://b2b.sg560.com/member/buy/mBuy,waitcheck882380009052016003126.html
                                        managerurl = string.Format("http://b2b.sg560.com/member/buy/mBuy,waitcheck{0}.html", myhttp.sgid);
                                        r = myhttp.HttpGet(managerurl, "");
                                        titleurl = myhttp.GetHtmlahref(r.Html.ToString(), txtgytitle);
                                    }
                                    lvi.SubItems[1].Text = titleurl;
                                    lsvdaifa.Items.RemoveAt(lvi.Index); // 按索引移除 
                                    lsvchenggong.Items.Add(lvi.Clone() as ListViewItem);
                                    UpdateTabNum();
                                    txttishi.Text += "链接:" + titleurl + "\r\n";
                                    //随机等待0秒
                                    //ping baidu                                    
                                    baidumsg = myhttp.postToPing(titleurl);
                                    txttishi.Text += "链接ping给百度完毕\r\n";
                                    //等待秒数
                                    if (havecont > 1)
                                    {
                                        sleeptime = stime + rnd.Next(etime - stime);
                                        txttishi.Text += "随机等待" + sleeptime + "秒。\r\n";
                                        waitsecond = sleeptime;
                                        isstarttime = true;
                                        Thread.Sleep(sleeptime * 1000);

                                    }
                                    else
                                    {
                                        txttishi.Text += "最后一条数据发送完成！\r\n";
                                    }
                                    lasterror = "";
                                    continue;//再发送本栏目信息
                                }
                                else
                                {
                                    if (html.Length > 0)
                                    {
                                        if (html.Contains("alert"))
                                        {
                                            string temp = html.Substring(html.LastIndexOf("alert") + 7);
                                            errormsg = temp.Substring(0, temp.IndexOf(")") - 1);
                                            if (errormsg.Contains("已经发布了"))
                                            {
                                                txttishi.Text += "提示信息：本栏发布数量已完成！" + errormsg + "\r\n";
                                                fb4 = false;
                                            }
                                            else
                                            {
                                                txttishi.Text += "出错:" + errormsg + "\r\n";
                                                lvi.SubItems[1].Text = errormsg;
                                                lsvdaifa.Items.RemoveAt(lvi.Index); // 按索引移除 
                                                lsvshibai.Items.Add(lvi.Clone() as ListViewItem);
                                                UpdateTabNum();
                                                if (lasterror != errormsg)
                                                {
                                                    lasterror = errormsg;
                                                    continue;
                                                }
                                                else
                                                {
                                                    lasterror = "";
                                                    txttishi.Text += "重复出错，已自动停止！\r\n";
                                                    isstoppub = true;
                                                    if (t != null)
                                                        t.Abort();
                                                    return;
                                                }
                                            }
                                        }
                                        else if (html.Contains("Object moved"))
                                        {
                                            txttishi.Text += "出错:用户已退出系统，请重新登录！\r\n";
                                            isstoppub = true;
                                            if (t != null)
                                                t.Abort();
                                            return;

                                        }
                                        else if (html.Contains("无法解析此远程名称") || html.Contains("无法连接到远程服务器") || html.Contains("remote name could not be resolved"))
                                        {
                                            lvi.SubItems[1].Text = "网络无法连接！";
                                            lsvdaifa.Items.Remove(lvi); // 按索引移除 
                                            lsvshibai.Items.Add(lvi.Clone() as ListViewItem);
                                            txttishi.Text += "网络无法连接！\r\n";
                                            sleeptime = stime + rnd.Next(etime - stime);
                                            txttishi.Text += "随机等待" + sleeptime + "秒。\r\n";
                                            waitsecond = sleeptime;
                                            isstarttime = true;
                                            Thread.Sleep(sleeptime * 1000);
                                            continue;//再发送本栏目信息
                                        }
                                        else
                                        {
                                            txttishi.Text += "出错:情况未知，请查看日志！\r\n";
                                            AShelp.SaveTXT(html, Application.StartupPath + "\\错误记录\\" + title + ".txt");

                                        }
                                    }
                                    else
                                    {
                                        txttishi.Text += "出错:没有收到响应！\r\n";

                                    }
                                }
                            }
                        }
                        #endregion

                        #region 资讯发布
                        if (cfb3)
                        {
                            if (fb3)
                            {
                                title = lvi.Text;
                                txttishi.Text += "当前正在发布的文章为:" + title + "。\r\n";
                                txtgytitle = title.Trim();
                                content = AShelp.LoadHtml(htmllist[rnd.Next(htmllist.Count)]);
                                content = ReplaceHTMLWZ(content, title);
                                if (prehtml != "")
                                    txtgydesc = content + prehtml;
                                else
                                    txtgydesc = content;
                                if (txtPics.Lines.Length > 0)
                                {
                                    hidimgb1 = pics[rnd.Next(pics.Length)];
                                    hidimg1 = pics[rnd.Next(pics.Length)];
                                    hidimgb2 = pics[rnd.Next(pics.Length)];
                                    hidimg2 = pics[rnd.Next(pics.Length)];
                                    hidimgb3 = pics[rnd.Next(pics.Length)];
                                    hidimg3 = pics[rnd.Next(pics.Length)];
                                }
                                strtemp.Remove(0, strtemp.Length);
                                strtemp.Append(strpost.ToString());
                                strtemp.Remove(0, strtemp.Length);
                                r = myhttp.HttpGet(httppubnew, "");
                                hidtitlc = myhttp.GetHtmlID(r.Html.ToString(), "input", "hidtitIc");
                                //hidtltIc
                                string __EVENTVALIDATION = "";
                                __EVENTVALIDATION = myhttp.GetHtmlID(r.Html.ToString(), "input", "__EVENTVALIDATION");
                                hidtltIc = myhttp.GetHtmlID(r.Html.ToString(), "input", "hidtltIc");
                                hidpic = myhttp.GetHtmlID(r.Html.ToString(), "input", "hidplo");
                                hiddesc = myhttp.GetHtmlID(r.Html.ToString(), "input", "hiddesc");
                                __VIEWSTATE = myhttp.GetHtmlID(r.Html.ToString(), "input", "__VIEWSTATE");
                                //txtgydesc = HttpUtility.HtmlEncode(txtgydesc);
                                NameValueCollection nvc = new NameValueCollection();
                                nvc.Add("hidtitIc", hidtitlc);
                                nvc.Add("hidplo", hidpic);
                                nvc.Add("hiddesc", hiddesc);
                                nvc.Add("hidtltIc", hidtltIc);
                                nvc.Add("__VIEWSTATE", __VIEWSTATE);
                                nvc.Add("__EVENTVALIDATION", __EVENTVALIDATION);
                                nvc.Add("newsType", newsType);
                                nvc.Add("newsTitle", txtgytitle);
                                nvc.Add("newsField", "");
                                nvc.Add("newsContent", txtgydesc);
                                nvc.Add("cid", cid);
                                nvc.Add("releaseBu", sReleaseButton);
                                nvc.Add("hidcategory", newscategory);
                                string html = myhttp.HttpUploadFile(urlnew, nvc);
                                if (html.Contains("su()//"))
                                {
                                    //发布成功。
                                    txttishi.Text += "标题:" + title + "发布成功。\r\n";
                                    managerurl = myhttp.GetHtmlValue(html, "a", "cur", "class", "href");
                                    if (!managerurl.Contains("http//"))
                                    {
                                        managerurl = "http://b2b.sg560.com/member/shop/" + managerurl;

                                    }
                                    r = myhttp.HttpGet(managerurl, "");
                                    titleurl = myhttp.GetHtmlahref(r.Html.ToString(), txtgytitle);
                                    lvi.SubItems[1].Text = titleurl;
                                    lsvdaifa.Items.RemoveAt(lvi.Index); // 按索引移除 
                                    lsvchenggong.Items.Add(lvi.Clone() as ListViewItem);
                                    UpdateTabNum();
                                    txttishi.Text += "链接:" + titleurl + "\r\n";
                                    //随机等待0秒
                                    //ping baidu                                    
                                    baidumsg = myhttp.postToPing(titleurl);
                                    txttishi.Text += "链接ping给百度完毕\r\n";
                                    //等待秒数
                                    if (havecont > 1)
                                    {
                                        sleeptime = stime + rnd.Next(etime - stime);
                                        txttishi.Text += "随机等待" + sleeptime + "秒。\r\n";
                                        waitsecond = sleeptime;
                                        isstarttime = true;
                                        Thread.Sleep(sleeptime * 1000);

                                    }
                                    else
                                    {
                                        txttishi.Text += "最后一条数据发送完成！\r\n";
                                    }
                                    lasterror = "";
                                    continue;//再发送本栏目信息
                                }
                                else
                                {
                                    if (html.Length > 0)
                                    {
                                        if (html.Contains("alert"))
                                        {
                                            string temp = html.Substring(html.LastIndexOf("alert") + 7);
                                            errormsg = temp.Substring(0, temp.IndexOf(")") - 1);
                                            if (errormsg.Contains("已经发布了"))
                                            {
                                                txttishi.Text += "提示信息：本栏发布数量已完成！" + errormsg + "\r\n";
                                                fb3 = false;
                                            }
                                            else
                                            {
                                                txttishi.Text += "出错:" + errormsg + "\r\n";
                                                lvi.SubItems[1].Text = errormsg;
                                                lsvdaifa.Items.RemoveAt(lvi.Index); // 按索引移除 
                                                lsvshibai.Items.Add(lvi.Clone() as ListViewItem);
                                                UpdateTabNum();
                                                if (lasterror != errormsg)
                                                {
                                                    lasterror = errormsg;
                                                    continue;
                                                }
                                                else
                                                {
                                                    lasterror = "";
                                                    txttishi.Text += "重复出错，已自动停止！\r\n";
                                                    isstoppub = true;
                                                    if (t != null)
                                                        t.Abort();
                                                    return;
                                                }
                                            }
                                        }
                                        else if (html.Contains("Object moved"))
                                        {
                                            txttishi.Text += "出错:用户已退出系统，请重新登录！\r\n";
                                            isstoppub = true;
                                            if (t != null)
                                                t.Abort();
                                            return;

                                        }
                                        else if (html.Contains("无法解析此远程名称") || html.Contains("无法连接到远程服务器") || html.Contains("remote name could not be resolved"))
                                        {
                                            lvi.SubItems[1].Text = "网络无法连接！";
                                            lsvdaifa.Items.Remove(lvi); // 按索引移除 
                                            lsvshibai.Items.Add(lvi.Clone() as ListViewItem);
                                            txttishi.Text += "网络无法连接！\r\n";
                                            sleeptime = stime + rnd.Next(etime - stime);
                                            txttishi.Text += "随机等待" + sleeptime + "秒。\r\n";
                                            waitsecond = sleeptime;
                                            isstarttime = true;
                                            Thread.Sleep(sleeptime * 1000);
                                            continue;//再发送本栏目信息
                                        }
                                        else
                                        {
                                            txttishi.Text += "出错:情况未知，请查看日志！\r\n";
                                            AShelp.SaveTXT(html, Application.StartupPath + "\\错误记录\\" + title + ".txt");

                                        }
                                    }
                                    else
                                    {
                                        txttishi.Text += "出错:没有收到响应！\r\n";

                                    }
                                }
                            }
                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        if(!(ex.Message.Contains("正在中止线程")|| ex.Message.Contains("aborted")))
                        {
                        lvi.SubItems[1].Text = ex.Message;
                        lsvdaifa.Items.Remove(lvi); // 按索引移除 
                        lsvshibai.Items.Add(lvi.Clone() as ListViewItem);
                        txttishi.Text += ex.Message + "\r\n";
                        sleeptime = stime + rnd.Next(etime - stime);
                        txttishi.Text += "随机等待" + sleeptime + "秒。\r\n";
                        waitsecond = sleeptime;
                        isstarttime = true;
                        Thread.Sleep(sleeptime * 1000);
                        }
                    }

                }
                else
                {
                    if (ispausd)
                    {
                        if (!txttishi.Text.EndsWith("文章发布暂停。\r\n"))
                            txttishi.Text += "文章发布暂停。\r\n";
                    }
                    else
                    {
                        if (!txttishi.Text.EndsWith("文章发布停止。\r\n"))
                            txttishi.Text += "文章发布停止。\r\n";
                    }

                    t = null;
                    return;
                }
                havecont = 0;
                havecont = lsvdaifa.Items.Count;
                label45.Text = string.Format("共有{0}个信息待发", havecont);
            }
            txttishi.Text += "文章发布完。\r\n";
            isstoppub = true;
        }

        private void UpdateTabNum()
        {
            label45.Text = string.Format("共有{0}个信息待发", lsvdaifa.Items.Count);
            label45.Refresh();
            tabControl5.TabPages[0].Text = string.Format("待发列表({0})", lsvdaifa.Items.Count);
            tabControl5.TabPages[1].Text = string.Format("成功列表({0})", lsvchenggong.Items.Count);
            tabControl5.TabPages[2].Text = string.Format("失败列表({0})", lsvshibai.Items.Count);
            tabControl5.Refresh();
        }

        public string ReplaceKeywords(string wz)
        {
            if (wz.Trim() != "")
            {
                Regex r;
                Random rnd = new Random();
                string[] txt;
                while (wz.Contains("【主变量】"))
                {
                    r = new Regex("【主变量】");
                    txt = txtzhubl.Lines;
                    if (txt.Length > 0)
                    {
                        string t = txt[rnd.Next(txt.Length)];
                        wz = r.Replace(wz, t, 1);
                    }
                    else
                    {
                        break;
                    }
                }
                while (wz.Contains("【变量1】"))
                {
                    r = new Regex("【变量1】");
                    txt = txtbl1.Lines;
                    if (txt.Length > 0)
                    {
                        string t = txt[rnd.Next(txt.Length)];
                        wz = r.Replace(wz, t, 1);
                    }
                    else
                    {
                        break;
                    }
                }
                while (wz.Contains("【变量2】"))
                {
                    r = new Regex("【变量2】");
                    txt = txtbl2.Lines;
                    if (txt.Length > 0)
                    {
                        string t = txt[rnd.Next(txt.Length)];
                        wz = r.Replace(wz, t, 1);
                    }
                    else
                    {
                        break;
                    }
                }
                while (wz.Contains("【变量3】"))
                {
                    r = new Regex("【变量3】");
                    txt = txtbl3.Lines;
                    if (txt.Length > 0)
                    {
                        string t = txt[rnd.Next(txt.Length)];
                        wz = r.Replace(wz, t, 1);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return wz;

        }
        public string ReplaceHTMLWZ(string wz, string title)
        {
            Regex r;
            Random rnd = new Random();
            string[] txt;
            string mybl = "";
            if (wz.Contains("【标题】"))
            {
                wz = wz.Replace("【标题】", title);
            }
            if (txtTitle.Text.Contains("【主变量】"))
            {
                foreach (string z in txtzhubl.Lines)
                {
                    if (title.Contains(z))
                    {
                        mybl = z;
                        break;
                    }
                }
                wz = wz.Replace("【主变量】", mybl);
            }
            else
            {
                while (wz.Contains("【主变量】"))
                {
                    r = new Regex("【主变量】");
                    txt = AShelp.delspaceStrings(txtzhubl.Lines);
                    if (txt.Length > 0)
                    {
                        string t = txt[rnd.Next(txt.Length)];
                        wz = r.Replace(wz, t, 1);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (txtTitle.Text.Contains("【变量1】"))
            {
                mybl = "";
                foreach (string z in txtbl1.Lines)
                {
                    if (title.Contains(z))
                    {
                        mybl = z;
                        break;
                    }
                }
                wz = wz.Replace("【变量1】", mybl);
            }
            else
            {
                while (wz.Contains("【变量1】"))
                {
                    r = new Regex("【变量1】");
                    txt = AShelp.delspaceStrings(txtbl1.Lines);
                    if (txt.Length > 0)
                    {
                        string t = txt[rnd.Next(txt.Length)];
                        wz = r.Replace(wz, t, 1);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (txtTitle.Text.Contains("【变量2】"))
            {
                mybl = "";
                foreach (string z in txtbl2.Lines)
                {
                    if (title.Contains(z))
                    {
                        mybl = z;
                        break;
                    }
                }
                wz = wz.Replace("【变量2】", mybl);
            }
            else
            {
                while (wz.Contains("【变量2】"))
                {
                    r = new Regex("【变量2】");
                    txt = AShelp.delspaceStrings(txtbl2.Lines);
                    if (txt.Length > 0)
                    {
                        string t = txt[rnd.Next(txt.Length)];
                        wz = r.Replace(wz, t, 1);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (txtTitle.Text.Contains("【变量3】"))
            {
                mybl = "";
                foreach (string z in txtbl3.Lines)
                {
                    if (title.Contains(z))
                    {
                        mybl = z;
                        break;
                    }
                }
                wz = wz.Replace("【变量3】", mybl);
            }
            else
            {
                while (wz.Contains("【变量3】"))
                {
                    r = new Regex("【变量3】");
                    txt = AShelp.delspaceStrings(txtbl3.Lines);
                    if (txt.Length > 0)
                    {
                        string t = txt[rnd.Next(txt.Length)];
                        wz = r.Replace(wz, t, 1);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            while (wz.Contains("【句子】"))
            {
                r = new Regex("【句子】");
                if (radioButton4.Checked)
                {
                    
                    txt = AShelp.delspaceStrings(txtjz.Lines);                    
                }
                else
                {
                    txt = AShelp.delspaceStrings(txtjz.Text.Split(new string[] { textBox10.Text.Trim() }, StringSplitOptions.RemoveEmptyEntries));
                }
                if (txt.Length > 0)
                {
                    string t = txt[rnd.Next(txt.Length)];
                    wz = r.Replace(wz, t, 1);
                }
                else
                {
                    break;
                }
            }
            while (wz.Contains("【随机图片】"))
            {
                r = new Regex("【随机图片】");
                txt = AShelp.delspaceStrings(txtrandpic.Lines);
                if (txt.Length > 0)
                {
                    string t = txt[rnd.Next(txt.Length)];

                    wz = r.Replace(wz, "<img src='" + t + "' />", 1);
                }
                else
                {
                    break;
                }
            }
            while (wz.Contains("【随机链接】"))
            {
                r = new Regex("【随机链接】");
                txt = AShelp.delspaceStrings(txtranda.Lines);
                if (txt.Length > 0)
                {
                    string t = txt[rnd.Next(txt.Length)];
                    wz = r.Replace(wz, "<a href='" + t + "'>" + t + "</a>", 1);
                }
                else
                {
                    break;
                }
            }
            while (wz.Contains("【段落1】"))
            {
                r = new Regex("【段落1】");
                if (radioButton9.Checked)
                {
                    txt = txtdl1.Lines;
                }
                else
                {
                    txt = AShelp.delspaceStrings(txtdl1.Text.Split(new string[] { textBox11.Text.Trim() }, StringSplitOptions.RemoveEmptyEntries));
                }
                if (txt.Length > 0)
                {
                    string t = txt[rnd.Next(txt.Length)];
                    wz = r.Replace(wz, t, 1);
                }
                else
                {
                    break;
                }
            }
            while (wz.Contains("【段落2】"))
            {
                r = new Regex("【段落2】");
                if (radioButton11.Checked)
                {
                    txt = txtdl2.Lines;
                }
                else
                {
                    txt = AShelp.delspaceStrings(txtdl2.Text.Split(new string[] { textBox12.Text.Trim() }, StringSplitOptions.RemoveEmptyEntries));
                }
                
                if (txt.Length > 0)
                {
                    string t = txt[rnd.Next(txt.Length)];
                    wz = r.Replace(wz, t, 1);
                }
                else
                {
                    break;
                }
            }
            while (wz.Contains("【段落3】"))
            {
                r = new Regex("【段落3】");
                if (radioButton13.Checked)
                {
                    txt = txtdl3.Lines;
                }
                else
                {
                    txt = AShelp.delspaceStrings(txtdl3.Text.Split(new string[] { textBox13.Text.Trim() }, StringSplitOptions.RemoveEmptyEntries));
                }
                if (txt.Length > 0)
                {
                    string t = txt[rnd.Next(txt.Length)];
                    wz = r.Replace(wz, t, 1);
                }
                else
                {
                    break;
                }
            }
            while (wz.Contains("【段落4】"))
            {
                r = new Regex("【段落4】");
                if (radioButton15.Checked)
                {
                    txt = txtdl4.Lines;
                }
                else
                {
                    txt = AShelp.delspaceStrings(txtdl4.Text.Split(new string[] { textBox14.Text.Trim() }, StringSplitOptions.RemoveEmptyEntries));
                }
                if (txt.Length > 0)
                {
                    string t = txt[rnd.Next(txt.Length)];
                    wz = r.Replace(wz, t, 1);
                }
                else
                {
                    break;
                }
            }
            while (wz.Contains("【段落5】"))
            {
                r = new Regex("【段落5】");
                if (radioButton17.Checked)
                {
                    txt = txtdl5.Lines;
                }
                else
                {
                    txt = AShelp.delspaceStrings(txtdl5.Text.Split(new string[] { textBox15.Text.Trim() }, StringSplitOptions.RemoveEmptyEntries));
                }
                if (txt.Length > 0)
                {
                    string t = txt[rnd.Next(txt.Length)];
                    wz = r.Replace(wz, t, 1);
                }
                else
                {
                    break;
                }
            }
            while (wz.Contains("【段落6】"))
            {
                r = new Regex("【段落6】");
                if (radioButton21.Checked)
                {
                    txt = txtdl6.Lines;
                }
                else
                {
                    txt = AShelp.delspaceStrings(txtdl6.Text.Split(new string[] { textBox18.Text.Trim() }, StringSplitOptions.RemoveEmptyEntries));
                }
                if (txt.Length > 0)
                {
                    string t = txt[rnd.Next(txt.Length)];
                    wz = r.Replace(wz, t, 1);
                }
                else
                {
                    break;
                }
            }
            while (wz.Contains("【年】"))
            {
                r = new Regex("【年】");
                string t = DateTime.Now.Year.ToString();
                wz = r.Replace(wz, t, 1);
            }
            while (wz.Contains("【月】"))
            {
                r = new Regex("【月】");
                string t = DateTime.Now.Month.ToString();
                wz = r.Replace(wz, t, 1);
            }
            while (wz.Contains("【日】"))
            {
                r = new Regex("【日】");
                string t = DateTime.Now.Day.ToString();
                wz = r.Replace(wz, t, 1);
            }
            wz = wz.Replace("&nbsp;", " ");
            return wz;

        }

        private void txtrandpic_MouseClick(object sender, MouseEventArgs e)
        {
            if (txtrandpic.Lines.Length > 0)
            {
                string path = "";
                ispics = false;
                int index = txtrandpic.GetFirstCharIndexOfCurrentLine();//得到当前行第一个字符的索引
                int line = txtrandpic.GetLineFromCharIndex(index);//得到当前行的行号,从0开始，习惯是从1开始，所以+1.
                path = txtrandpic.Lines[line];
                if (path != "" && path.StartsWith("http://"))
                {
                    lblpicpath.Text = string.Format("{0}", path);
                    pictureBox1.ImageLocation = path;
                }
                else
                {
                    lblpicpath.Text = string.Format("{0}", "");
                    pictureBox1.ImageLocation = "";

                }
            }


        }

        private void txtPics_MouseClick(object sender, MouseEventArgs e)
        {
            if (txtPics.Lines.Length > 0)
            {
                string path = "";
                ispics = true;
                int index = txtPics.GetFirstCharIndexOfCurrentLine();//得到当前行第一个字符的索引
                int line = txtPics.GetLineFromCharIndex(index);//得到当前行的行号,从0开始，习惯是从1开始，所以+1.
                path = txtPics.Lines[line];
                if (path != "" && path.StartsWith("http://"))
                {
                    lblpicpath.Text = string.Format("{0}", path);
                    pictureBox1.ImageLocation = path;
                }
                else
                {
                    lblpicpath.Text = string.Format("{0}", "");
                    pictureBox1.ImageLocation = "";

                }
            }


        }

        private void button100_Click(object sender, EventArgs e)
        {
            frmgetpic f = new frmgetpic(this);
            f.TopMost = true;
            f.Show();
        }


        private void button101_Click(object sender, EventArgs e)
        {
            if (ispics)
            {
                string[] s = txtPics.Lines;
                txtPics.Text = "";
                List<string> list = new List<string>();
                foreach (string t in s)
                {
                    if (t != lblpicpath.Text && t != "")
                    {
                        list.Add(t);
                    }
                }
                txtPics.Lines = list.ToArray();
            }
            else
            {
                string[] s = txtrandpic.Lines;
                txtrandpic.Text = "";
                List<string> list = new List<string>();
                foreach (string t in s)
                {
                    if (t != lblpicpath.Text && t != "")
                    {
                        list.Add(t);
                    }
                }
                txtrandpic.Lines = list.ToArray();

            }

        }

        private void btnimgclear_Click(object sender, EventArgs e)
        {
            txtPics.Text = "";
        }

        private void txtdl4_TextChanged(object sender, EventArgs e)
        {
            label43.Text = string.Format("段落4，共有{0}行", txtdl4.Lines.Length);
        }

        private void txtdl3_TextChanged(object sender, EventArgs e)
        {
            label40.Text = string.Format("段落3，共有{0}行", txtdl3.Lines.Length);
        }

        private void txtdl2_TextChanged(object sender, EventArgs e)
        {
            label37.Text = string.Format("段落2，共有{0}行", txtdl2.Lines.Length);
        }

        private void txtdl1_TextChanged(object sender, EventArgs e)
        {
            label32.Text = string.Format("段落1，共有{0}行", txtdl1.Lines.Length);
        }

        private void txttishi_TextChanged(object sender, EventArgs e)
        {
            this.txttishi.Select(this.txttishi.TextLength, 0);//光标定位到文本最后
            this.txttishi.ScrollToCaret();//滚动到光标处
        }

        private void button62_Click(object sender, EventArgs e)
        {
            isstoppub = true;
            ispausd = true;
            isstarttime = false;
            if (!txttishi.Text.EndsWith("文章发布暂停。\r\n"))
                txttishi.Text += "文章发布暂停。\r\n";
            if (t != null)
                t.Abort();


        }

        private void button63_Click(object sender, EventArgs e)
        {
            isstoppub = true;
            ispausd = false;
            isstarttime = false;
            if (!txttishi.Text.EndsWith("文章发布停止。\r\n"))
                txttishi.Text += "文章发布停止。\r\n";
            if (t != null)
                t.Abort();
        }

        private void button99_Click(object sender, EventArgs e)
        {
            if (myhttp.islogin == "OK")
            {
                string s = myhttp.Refreshtitle();
                MessageBox.Show(s);
            }
            else
            {
                MessageBox.Show("请登录后再操作！");
            }
        }

        private void lsvchenggong_DoubleClick(object sender, EventArgs e)
        {

        }

        private void lsvchenggong_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListViewHitTestInfo info = lsvchenggong.HitTest(e.X, e.Y);
            if (info.Item != null)
            {
                var videoitem = info.Item as ListViewItem;
                if (videoitem != null)
                {
                    string url = videoitem.SubItems[1].Text;
                    System.Diagnostics.Process.Start(url);
                }

            }
        }

        private void button73_Click(object sender, EventArgs e)
        {
            string url = "http://7xiex6.com1.z0.glb.clouddn.com/m%E6%95%8F%E6%84%9F%E8%AF%8D/guanggaofa.bin";
            myhttp.DownloadFile(url, Application.StartupPath + "\\guanggaofa.bin");
            MessageBox.Show("获取完成！");
        }

        private void button80_Click(object sender, EventArgs e)
        {
            string url = "http://7xiex6.com1.z0.glb.clouddn.com/m%E6%95%8F%E6%84%9F%E8%AF%8D/all.bin";
            myhttp.DownloadFile(url, Application.StartupPath + "\\all.bin");
            MessageBox.Show("获取完成！");
        }

        private void button65_Click(object sender, EventArgs e)
        {
            string gg = AShelp.LoadTXT(Application.StartupPath + "\\guanggaofa.bin");
            string all = AShelp.LoadTXT(Application.StartupPath + "\\all.bin");
            if (gg.Length > 0 && !gg.EndsWith("\r\n"))
            {
                gg = gg + "\r\n";
            }
            if (gg + all != "")
                textBox32.Text = gg + all;
            else
            {
                MessageBox.Show("还没有数据！");
            }
        }

        private void button87_Click(object sender, EventArgs e)
        {
            string gg = AShelp.LoadTXT(Application.StartupPath + "\\guanggaofa.bin");
            string all = AShelp.LoadTXT(Application.StartupPath + "\\all.bin");
            if (gg.Length > 0 && !gg.EndsWith("\r\n"))
            {
                gg = gg + "\r\n";
            }
            string allstr = gg + all;
            if (textBox31.Text.Trim() != "")
            {
                if (allstr.Length > 0 && !allstr.EndsWith("\r\n"))
                {
                    allstr = allstr + "\r\n";
                }
                allstr = allstr + textBox31.Text.Trim();

            }
            string[] s = allstr.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            string v = "";
            if (checkBox9.Checked)
            {
                v = txtzhubl.Text;
                if (v.Length > 0)
                    foreach (string si in s)
                    {
                        if (si.Length > 0)
                            v = v.Replace(si, "");
                    }
                txtzhubl.Text = v;
                textBox32.Text += "主变量替换完成！\r\n";
            }
            if (checkBox10.Checked)
            {
                v = txtbl1.Text;
                if (v.Length > 0)
                    foreach (string si in s)
                    {
                        if (si.Length > 0)
                            v = v.Replace(si, "");
                    }
                txtbl1.Text = v;
                textBox32.Text += "变量1替换完成！\r\n";
            }
            if (checkBox11.Checked)
            {
                v = txtbl2.Text;
                if (v.Length > 0)
                    foreach (string si in s)
                    {
                        if (si.Length > 0)
                            v = v.Replace(si, "");
                    }
                txtbl2.Text = v;
                textBox32.Text += "变量2替换完成！\r\n";
            }
            if (checkBox12.Checked)
            {
                v = txtbl3.Text;
                if (v.Length > 0)
                    foreach (string si in s)
                    {
                        if (si.Length > 0)
                            v = v.Replace(si, "");
                    }
                txtbl3.Text = v;
                textBox32.Text += "变量3替换完成！\r\n";
            }
            if (checkBox13.Checked)
            {
                v = txtjz.Text;
                if (v.Length > 0)
                    foreach (string si in s)
                    {
                        if (si.Length > 0)
                            v = v.Replace(si, "");
                    }
                txtjz.Text = v;
                textBox32.Text += "句子替换完成！\r\n";
            }
            if (checkBox14.Checked)
            {
                //内容模版
                string temp = "";
                for (int i = 0; i < ckbHtml.Items.Count; i++)
                {
                    temp = ckbHtml.GetItemText(ckbHtml.Items[i]);
                    txtmbname.Text = temp;
                    string html = AShelp.LoadHtml(temp);
                    if (html.Length > 0)
                    {
                        foreach (string si in s)
                        {
                            if (si.Length > 0)
                                html = html.Replace(si, "");
                        }
                        AShelp.SaveHtml(html, temp);
                    }

                }
                string htmle = htmlEditor1.BodyInnerHTML;
                if (htmle != null && htmle.Length > 0)
                {
                    foreach (string si in s)
                    {
                        if (si.Length > 0)
                            htmle = htmle.Replace(si, "");
                    }
                    htmlEditor1.BodyInnerHTML = htmle; ;
                }
                textBox32.Text += "内容模版替换完成！\r\n";
            }
            //MessageBox.Show("替换完成！");
        }

        private void ckbHtml_Click(object sender, EventArgs e)
        {
            string temp = "";
            int selectCount = ckbHtml.SelectedItems.Count; //SelectedItems.Count就是：取得值，表示SelectedItems集合的物件数目。 
            if (selectCount > 0)//若selectCount大於0，说明用户有选中某列。
            {

                temp = ckbHtml.GetItemText(ckbHtml.SelectedItems[0]);
                txtmbname.Text = temp;
                string html = AShelp.LoadHtml(temp);
                htmlEditor1.BodyInnerHTML = html;
                return;
            }
        }

        private void button88_Click(object sender, EventArgs e)
        {
            frmrepeat f = new frmrepeat();
            f.TopMost = true;
            f.Show();
        }

        private void button89_Click(object sender, EventArgs e)
        {
            frmrandom f = new frmrandom();
            f.TopMost = true;
            f.Show();
        }

        private void button90_Click(object sender, EventArgs e)
        {
            frmreplace f = new frmreplace();
            f.TopMost = true;
            f.Show();
        }

        private void button93_Click(object sender, EventArgs e)
        {
            frmwordtopic f = new frmwordtopic();
            f.TopMost = true;
            f.Show();
        }

        private void button92_Click(object sender, EventArgs e)
        {
            frmpiczip f = new frmpiczip();
            f.TopMost = true;
            f.Show();
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (isstarttime)
                if (lsvdaifa.Items.Count > 0)
                {
                    lsvdaifa.Items[0].SubItems[1].Text = string.Format("等待时间还有{0}秒", waitsecond);
                    waitsecond--;
                    if (waitsecond < 0)
                    {
                        isstarttime = false;
                    }
                }
                else
                {
                    isstarttime = false;
                }
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            if (DateTime.Now > shutstart)
            {
                DoExitWin(1);
            }
        }

        private void ckbshut_Click(object sender, EventArgs e)
        {
            if (ckbshut.Checked)
            {
                if (radioButton2.Checked)
                {
                    int t = 0;
                    int.TryParse(txtmini.Text, out t);
                    if (t > 5)
                    {
                        shutstart = DateTime.Now.AddMinutes(t);
                        timer3.Enabled = true;
                    }
                    else
                        MessageBox.Show("定时至少要5分钟！");
                }
            }
        }

        private void radioButton2_Click(object sender, EventArgs e)
        {
            if (ckbshut.Checked)
            {
                if (radioButton2.Checked)
                {
                    int t = 0;
                    int.TryParse(txtmini.Text, out t);
                    if (t > 5)
                    {
                        shutstart = DateTime.Now.AddMinutes(t);
                        timer3.Enabled = true;
                    }
                    else
                        MessageBox.Show("定时至少要5分钟！");
                }
            }

        }

        private void button65_Click_1(object sender, EventArgs e)
        {
            string temp = "";
            for (int i = 0; i < ckbHtml.Items.Count; i++)
            {
                if (ckbHtml.GetItemChecked(i))
                {
                    temp = ckbHtml.GetItemText(ckbHtml.Items[i]);
                    AShelp.DeleteHtml(temp);
                    ckbHtml.Items.RemoveAt(i);
                    i--;
                }
            }
        }

        private void button91_Click(object sender, EventArgs e)
        {
            frmpicadd f = new frmpicadd();
            f.TopMost = true;
            f.Show();
        }

        private void timer_heart_Tick(object sender, EventArgs e)
        {
            //string key = "AutoSend";
            //string iv = "weiwei@1";

            //string strPass = this._login_name + "|" + this._login_pass + "|" + Myinfo.sid + "|" + DateTime.Now;

            //string md5strPass = Tools.Encode(strPass, key, iv);

            //WebReference2.Heart hwm = new WebReference2.Heart();

            //try
            //{
            //    hwm.SetHeart(md5strPass);
            //}
            //catch (Exception ex)
            //{
            //    //if (ex.ToString().Contains("无法连接到远程服务器"))
            //    {
            //        timer_heart.Stop();
            //        MessageBox.Show("无法连接到远程服务器,请检查网络！");
            //        //SaveConfig();
            //        //Application.ExitThread();
            //    }

            //}
        }



        //更改密码
        private void 更改密码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmUpdatePass f = new frmUpdatePass(this._login_name, this._login_pass);
            f.TopMost = true;
            DialogResult ddr = f.ShowDialog();

            if (ddr == System.Windows.Forms.DialogResult.OK)
            {
                this._login_pass = f._newPass;//获取更改后的密码
            }
        }

        private void frmMain_Resize(object sender, EventArgs e)
        {
            //窗体最小化时  
            if (this.WindowState == FormWindowState.Minimized)
            {
                Myinfo.myfmain.Hide();
                Myinfo.myfmain.ShowInTaskbar = false;
                Myinfo.myfmain.TopMost = false;
            }
        }

        private void tabControl2_DrawItem(object sender, DrawItemEventArgs e)
        {
            SolidBrush p = new SolidBrush(Color.Red);
            SolidBrush b = new SolidBrush(Color.Black);
            SolidBrush y = new SolidBrush(Color.Yellow);
            StringFormat s = new StringFormat();
            s.Alignment = StringAlignment.Center;
            s.LineAlignment = StringAlignment.Center;
            Rectangle r = tabControl2.GetTabRect(e.Index);

            if (e.Index > 0)
            {
                e.Graphics.FillRectangle(y, r);
                e.Graphics.DrawString(this.tabControl2.TabPages[e.Index].Text, this.Font, p, r, s);
            }
            else
            {
                e.Graphics.DrawString(this.tabControl2.TabPages[e.Index].Text, this.Font, b, r, s);
            }
        }

        private void button81_Click(object sender, EventArgs e)
        {
            checkBox9.Checked = true;
            checkBox10.Checked = true;
            checkBox11.Checked = true;
            checkBox12.Checked = true;
            checkBox13.Checked = true;
            checkBox14.Checked = true;

        }

        private void button102_Click(object sender, EventArgs e)
        {
            string checkedname = "";
            int lsindex = -1;
            for (int i = 0; i < this.lsvConfig.Items.Count; i++)
            {
                if (this.lsvConfig.Items[i].Selected)
                {
                    checkedname = this.lsvConfig.Items[i].Text;
                    lsindex = i;
                    break;
                }
            }
            if (checkedname != "")
            {
                if (Myinfo.configname != checkedname)
                {
                    string err = AShelp.DelConfig(checkedname);
                    if (err == "")
                    {
                        this.lsvConfig.Items.RemoveAt(lsindex);
                        MessageBox.Show("删除成功！");
                    }
                    else
                        MessageBox.Show("删除不成功！" + err);

                }
                else
                {
                    MessageBox.Show("不能删除当前配置");

                }
            }
            else
            {
                MessageBox.Show("请选中一个配置");
            }

        }

        private void frmMain_Activated(object sender, EventArgs e)
        {
            //this.TopMost = false;
        }

        private void button103_Click(object sender, EventArgs e)
        {
            if (radioButton8.Checked)
            {
                string split = textBox11.Text.Trim();
                frmdlhtml f = new frmdlhtml();
                if (f.ShowDialog() == DialogResult.OK)
                {
                    if (txtdl1.Text.Trim().EndsWith(split)|| txtdl1.Text.Trim()=="")
                    {
                        txtdl1.Text += f.HTML;
                    }
                    else
                    {
                        txtdl1.Text += split;
                        txtdl1.Text += f.HTML;
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择自定义分割！");
            }
        }

        private void textBox17_TextChanged(object sender, EventArgs e)
        {
            label54.Text = string.Format("段落5，共有{0}行", txtdl5.Lines.Length);
        }

        private void textBox20_TextChanged(object sender, EventArgs e)
        {
            label57.Text = string.Format("段落6，共有{0}行", txtdl6.Lines.Length);
        }

        private void button113_Click(object sender, EventArgs e)
        {
            if (txtdl5.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【段落5】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("段落5没有数据");
        }

        private void button114_Click(object sender, EventArgs e)
        {
            if (txtdl6.Lines.Length > 0)
            {
                txtmbname.Focus();
                this.htmlEditor1.PasteIntoSelection("【段落6】");
                this.htmlEditor1.Focus();
            }
            else
                MessageBox.Show("段落6没有数据");
        }

        private void button110_Click(object sender, EventArgs e)
        {
            if (radioButton20.Checked)
            {
                string split = textBox18.Text.Trim();
                frmdlhtml f = new frmdlhtml();
                if (f.ShowDialog() == DialogResult.OK)
                {
                    if (txtdl6.Text.Trim().EndsWith(split) || txtdl6.Text.Trim() == "")
                    {
                        txtdl6.Text += f.HTML;
                    }
                    else
                    {
                        txtdl6.Text += split;
                        txtdl6.Text += f.HTML;
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择自定义分割！");
            }
        }

        private void button104_Click(object sender, EventArgs e)
        {
            if (radioButton10.Checked)
            {
                string split = textBox12.Text.Trim();
                frmdlhtml f = new frmdlhtml();
                if (f.ShowDialog() == DialogResult.OK)
                {
                    if (txtdl2.Text.Trim().EndsWith(split) || txtdl2.Text.Trim() == "")
                    {
                        txtdl2.Text += f.HTML;
                    }
                    else
                    {
                        txtdl2.Text += split;
                        txtdl2.Text += f.HTML;
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择自定义分割！");
            }
        }

        private void button105_Click(object sender, EventArgs e)
        {
            if (radioButton12.Checked)
            {
                string split = textBox13.Text.Trim();
                frmdlhtml f = new frmdlhtml();
                if (f.ShowDialog() == DialogResult.OK)
                {
                    if (txtdl3.Text.Trim().EndsWith(split) || txtdl3.Text.Trim() == "")
                    {
                        txtdl3.Text += f.HTML;
                    }
                    else
                    {
                        txtdl3.Text += split;
                        txtdl3.Text += f.HTML;
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择自定义分割！");
            }
        }

        private void button106_Click(object sender, EventArgs e)
        {
            if (radioButton14.Checked)
            {
                string split = textBox14.Text.Trim();
                frmdlhtml f = new frmdlhtml();
                if (f.ShowDialog() == DialogResult.OK)
                {
                    if (txtdl4.Text.Trim().EndsWith(split) || txtdl4.Text.Trim() == "")
                    {
                        txtdl4.Text += f.HTML;
                    }
                    else
                    {
                        txtdl4.Text += split;
                        txtdl4.Text += f.HTML;
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择自定义分割！");
            }
        }

        private void button107_Click(object sender, EventArgs e)
        {
            if (radioButton16.Checked)
            {
                string split = textBox15.Text.Trim();
                frmdlhtml f = new frmdlhtml();
                if (f.ShowDialog() == DialogResult.OK)
                {
                    if (txtdl5.Text.Trim().EndsWith(split) || txtdl5.Text.Trim() == "")
                    {
                        txtdl5.Text += f.HTML;
                    }
                    else
                    {
                        txtdl5.Text += split;
                        txtdl5.Text += f.HTML;
                    }
                }
            }
            else
            {
                MessageBox.Show("请选择自定义分割！");
            }
        }
    }
}
